{"id":67,"date":"2011-09-28T01:11:51","date_gmt":"2011-09-28T01:11:51","guid":{"rendered":"http:\/\/info.ffteixeira.net\/2011\/09\/28\/cakephp-multi-model-view\/"},"modified":"2011-09-28T01:11:51","modified_gmt":"2011-09-28T01:11:51","slug":"cakephp-multi-model-view","status":"publish","type":"post","link":"https:\/\/blog.ffteixeira.net\/?p=67","title":{"rendered":"CakePHP multi-model view"},"content":{"rendered":"<p>If your using the latest 1.2 code, check out Model::saveAll in the api<\/p>\n<p>eg. Your view might look something like this:<br \/>\n<!--more--><br \/>\nIf your using the latest 1.2 code, check out Model::saveAll in the api<\/p>\n<p>eg. Your view might look something like this:<!--more--><\/p>\n<pre><code>echo $form-&gt;create('User', array('action'=&gt;'add'); echo $form-&gt;input('User.name'); echo $form-&gt;input('Address.line_1'); echo $form-&gt;input('Contact.tel'); echo $form-&gt;end('Save'); <\/code><\/pre>\n<p>Then in your Users controller add method you&#8217;d have something like:<\/p>\n<pre><code>...if($this-&gt;User-&gt;saveAll($this-&gt;data)){ \u00a0$this-&gt;Session-&gt;setFlash('Save Successful'); \u00a0$this-&gt;redirect(array('action'=&gt;'index')); }else{ \u00a0$this-&gt;Session-&gt;setFlash('Please review the form for errors'); }... <\/code><\/pre>\n<p>In your User model you will need something like:<\/p>\n<pre><code>var $hasOne = array('Address','Contact'); <\/code><\/pre>\n<p>Hope that helps!<\/p>\n<p><a href=\"http:\/\/api.cakephp.org\/class_model.html#49f295217028004b5a723caf086a86b1\">http:\/\/api.cakephp.org\/class_model.html#49f295217028004b5a723caf086a86b1<\/a><\/p>\n<p>From: http:\/\/stackoverflow.com\/questions\/110232\/cakephp-multi-model-view<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If your using the latest 1.2 code, check out Model::saveAll in the api eg. Your view might look something like this:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67"}],"version-history":[{"count":0,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ffteixeira.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}