嘿伙计们请帮助我,我想通过一个表单更新两个表数据,但数据只在一个表中更新并插入到第二个表中,而不是更新现有记录。这是我的代码-
查看文件:
echo $this->Form->create('Question');
echo $this->Form->input('question');
foreach (range(0,2) as $index)
{
echo $this->Form->input('Option.'.$index.'.poll_options');
}
echo $this->Form->input('id',array('type'=>'hidden'));
echo $this->Form->end('Save Poll');
控制器文件:
$data=$this->Question->findById($id);
if($this->request->is('post') || $this->request->is('put'))
{
if($this->Question->saveAll($this->request->data))
{
$this->Session->setFlash('Question has been updated');
$this->redirect(array('action'=>'index'));
}
else
{
$this->Session->setFlash('Question has not been updated');
}
}
if(!$this->request->data)
{
$this->request->data=$data;
}