CakePHP multi-model view
cakephp, cakephp-1.2, entity-relationship, model-driven
Solution
If your using the latest 1.2 code, check out Model::saveAll in the api
eg. Your view might look something like this:
echo $form->create('User', array('action' => 'add');
echo $form->input('User.name');
echo $form->input('Address.line_1');
echo $form->input('Contact.tel');
echo $form->end('Save');
Then in your Users controller add method you'd have something like:
...
if($this->User->saveAll($this->data)) {
$this->Session->setFlash('Save Successful');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Please review the form for errors');
}
...
In your User model you will need something like:
var $hasOne = array('Address', 'Contact');
Hope that helps!
http://api.cakephp.org/class_model.html#49f295217028004b5a723caf086a86b1
Problem
I am creating a website in CakePHP and I am kind of new on it. I couldn't find good resources on this matter, so there you go: I have a three table structure for registering users: `Users`, `Addresses` and `Contacts`. I have to build a view with info of all three tables like: ``` Full Name: [ ] (from Users) Shipping Address: [ ] (from Address) Mobile Phone: [ ] (from Contact) e-Mail Address: [ ] (from Contact) ``` What is the best way to deal with this situation. Specially for saving. Creating a new Model to represent this, that will have a `save()` method itself (Maybe a sql view in the database) Create a Controller to deal with this View that `bind`s or `unbind`s info I wonder still how I will handle both contacts as they will be 2 different `INSERT`'s Any hint or resources I can dig of I will be glad.