On Sun, Apr 17, 2011 at 7:53 AM, John Eke <[email protected]> wrote:
> I was wondering if there was an easy way to combine models into the
> same form if they are related to eachother. For example say there were
> two models Library and Book, and they were related (Library hasMany
> Book)
Hi John, Using FormHelpers you can loop through your associations and
have forms span associations like so in your view:
$this->Form->input('library.book.author', array(...)); or maybe, I'm
not exactly sure how cake expects the fields name to be, maybe its
$this->Form->input(library.book.N.author', array(...)); instead where
N is the index of the associated model in the generated array.
Then in your controller you would use the models save method like so:
$this->Library->saveAll($this->data);
or more granulay:
$this->Library->save($this->data);
and
$this->Library->Book->save($this->data['Book']);
Take a look at the manual, there are a few examples that do this, look
for Saving Related Data.
Regards, Yuka
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php