Thank you!

If I assign an id correctly, cake updates as I wanted!

On Mar 11, 12:23 am, josu jauregui <[email protected]> wrote:
> Hi! You may to assign an id to the object; if the object doesn´t have an id,
> cakephp creates a new record. Try this:
>
> function edit($id = null) {
>                if (!empty($this->data)) {
>                      * $this->Book->id=$id;*
>                        $this->Book->saveall($this->
>
>
>
> > data);
> >                        $this->redirect(array('action' => 'index'));
> >                }
> >                if (empty($this->data)) {
> >                        $this->data = $this->Book->read(null, $id);
> >                }
> >        }
>
> I hope it can help you. Bye!
>
> 2010/3/10 newtocake <[email protected]>
>
> > Hi, I want to update data of several tables when I edit them, but
> > somehow, it creates new records. :(   Does somebody have any idea?
>
> > books table   [id, name, user_id]
> > users table [id, name, password]
> > comments table [id, comment, user_id, book_id]
>
> > [books_controller]
>
> >        var $uses = array('Book','Comment');
>
> >        function edit($id = null) {
> >                if (!empty($this->data)) {
> >                        $this->Book->saveall($this->data);
> >                        $this->redirect(array('action' => 'index'));
> >                }
> >                if (empty($this->data)) {
> >                        $this->data = $this->Book->read(null, $id);
> >                }
> >        }
>
> > [book model]
>
> >        var $belongsTo = 'User';
> >        var $hasOne = 'Comment';
>
> > [index view]
>
> > <?php echo $html->link('Edit',array('action' => 'edit', $value['Book']
> > ['id'])); ?>
>
> > [edit view]
>
> > echo $form->create('Book');
> > echo $form->input('id');
> > echo $form->input('Book.name');
> > echo $form->input('User.name');
> > echo $form->input('Comment.comment');
> > echo $form->end('Submit');
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<cake-php%[email protected]>For
> >  more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to