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.

Cooked … Maybe CakePHP is a real PHP Framework and not a CMS wearing shuts. It troubles me the weird function name that you small script use .. like scrape and setFlash that all live in the same Controller or Parent… I don’t want to say anything bad about CakePHP , I am sure that some persons worked for that, without any other profit besides knowledge and I respect them. But when you decided to move to that framework you have to live with their community as well …

are you saying I shouldn't be asking this question here? and what's wrong with my function names?? (setFlash is part of CakePHP)

No it is ok that you asked here … but maybe the people that can help you with that kind of weird functions are those who invent them or use them, An I should say once more that since Cake is freeware I respect the people doing it with no profit except knowledge.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.