954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't Save [CakePHP]

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.

theweirdone
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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 …

jkon
Posting Whiz in Training
281 posts since Jan 2009
Reputation Points: 77
Solved Threads: 47
 

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

theweirdone
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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.

jkon
Posting Whiz in Training
281 posts since Jan 2009
Reputation Points: 77
Solved Threads: 47
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: