【发布时间】:2011-09-08 06:10:50
【问题描述】:
我有两个模型,一个是Login,另一个是Userdetail。我使用hasone 关系在两个模型中保存了模型Login 的数据。
请告诉我如何编辑它们。
我使用以下代码保存在我的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
}
}
}
【问题讨论】: