I have two models, one is Login
and the other is Userdetail
. I saved data from model Login
in both models using the hasone
relationship.
Please let me know how it would be possible to edit them.
I used the following code for save in my add.ctp
file:
echo $form->create('Login', array('action'=>'add'));
echo $form->input('first_name');
echo $form->input('last_name');
echo $form->input('email');
echo $form->input('user_name');
echo $form->input('password');
echo $form->input('Userdetail.first_name');
echo $form->input('Userdetail.last_name');
echo $form->input('Userdetail.designation');
echo $form->input('Userdetail.contact');
echo $form->input('Userdetail.address');
echo $form->end('Add');
and in controller i used :
function add()
{
if (!empty($this->data))
{
if ($this->Login->saveAll($this->data))
{
// User and Profile created successfully
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
else
{
// Error creating user
}
}
}