我有两个模型,一个是,一个Login
是Userdetail
。我使用该关系将模型中的数据保存Login
在两个模型中。hasone
请让我知道如何编辑它们。
我使用以下代码保存在我的add.ctp
文件中:
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
}
}
}