try with $this->TurisSit->saveall($this->data); S. > TuristSit
On Jun 17, 2011, at 12:17 AM, csoria wrote: > Hi i'm new in cakephp > > I'm starting to do an application and i'm wondering if i can save in > different models from one form. > > For more specific: > > I have three models > TuristSite: Has One Contact > Contact: Belongs To a TuristSite, Has Many Telephones > Telephone: Belongs To a Contact > > I want to put all the information for this three models in one form in > the action turist_sites/add > > > In the add.ctp of turist_sites > echo $this->Form->input('TuristSite.name'); > echo $this->Form->input('TuristSite.logo', > array('type'=>'file')); > echo $this->Form->input('TuristSite.website'); > echo $this->Form->input('TuristSite.address'); > echo $this->Form->input('TuristSite.description'); > echo $this->Form->hidden('TuristSite.votes', > array('value'=>'0')); > echo $this->Form->hidden('TuristSite.views', > array('value'=>'0')); > echo $this->Form->input('TuristSite.User'); > > echo $this->Form->input('Contact.name'); > echo $this->Form->input('Contact.last_name'); > echo $this->Form->input('Contact.email'); > echo $this->Form->hidden('Contact.turist_site_id'); > > echo $this->Form->input('Thelephone.0.number); > echo $this->Form->hidden('Thelephone.0.contact_id); > echo $this->Form->input('Thelephone.1.number); > echo $this->Form->hidden('Thelephone.1.contact_id); > echo $this->Form->input('Thelephone.2.number); > echo $this->Form->hidden('Thelephone.2.contact_id); > > And this i have controller's add action > > $turistSiteData = $this->data['TuristSite']; > $contactData = $this->data['Contact']; > > if ($this->TuristSite->save($turistSiteData) { > if ($this->TuristSite->Contact- >> addContactTuristSite($this->TuristSite->id, $contactData)) { > $this->Session->setFlash(__('The > turist site has been saved', true)); > $this->redirect(array('action' => > 'index')); > } > else { > $this->TuristSite->delete($this- >> TuristSite->id, false); > $this->Session->setFlash(__('The > contact of the turist site could not be saved. Please, try again.', > true)); > } > > } > > And i have a function in the Contact Model > > > function addContactTuristSite($id = null, $data = null) { > if ($id == null && data == null){ > return false; > } > else{ > $data['Contact']['turist_site_id'] = $id; > return $this->save($data); > } > } > > When i run this, just save the information for the TuristSite and > insert a row in the Contacts table but just with the id and the > turist_site_id. > > I don't know if you understand my problem. And if this the best way to > do this. Any answer will be apreciate. > > -- > 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+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php