Monday, February 28, 2011

Re: Can't Save to DB

Hey
Thanks already for all the help.
I've changed my code, here's the new controller:

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
        if($this->Episode->saveAll($episodes['Episode'])){
            $this->Session->setFlash(__($count.' episodes were saved.', true));
        }
    }

I've also updated the scraper to return the array such as in the manual:

Array
(
    [Episode] => 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
                )
)

So now the saveAll() function should be working I think. Yet it still doesn't save anything to the database.
Should I put in a for loop and save each episode individually using the save() function? Is there any reason that would be more likely to work?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: