Hi,
I'm pretty new to CakePHP, and have been managing so far.
I've created a scraper that scrapes TV.com for episode information (episode number, airdate, title, description). The scraper works fine, and returns an array such as:
Array
(
[0] => Array
(
[name] => Stowaway
[number] => 17
[description] => No synopsis available. Write a synopsis.
[date] => 3/18/2011
[show_id] => 11
)
[1] => Array
(
[name] => Os
[number] => 16
[description] => While Walter attempts to figure out a way to stop the spread of vortexes on This Side, the team investigate a series of thefts committed by criminals who can control gravity.
[date] => 3/11/2011
[show_id] => 11
)
)
The array is definately there, because I can print_r it.
On to the controller. The controller is called episodes_controller, and has the usual CRUB actions, plus the scraper. I've added an action called addAll which calls the scraper and then is meant to save the array into the database using a foreach loop. Here's the code:
function addAll($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid show id entered', true));
//$this->redirect('/episodes');
}
$show = $this->requestAction('/shows/getTvById/'.$id); //gets the tv.com url
$episodes = $this->scrape($show, $id); //scrapes tv.com for the show
$this->set('episodes', $episodes); //sets $TVshowInfo for the view
$count = 0;
foreach ($episodes as $episode) {
$this->Episode->set($episode);
if($this->Episode->save()){
$count++;
}
}
$this->Session->setFlash(__($count.' episodes were saved.', true));
//$this->redirect('/episodes');
}
Every time I run it, the Flash message say's 0 episodes saved.
I've tried variations such as
if ($this->Episode->save($episode)){
with the same result.
Any suggestions would be welcome. Thanks.