嘿家伙请帮我在这我想更新两个表的数据通过一个单一的表格,但数据更新只在一个表中,并插入第二个表中,而不是更新现有的记录。这里是我的代码 -通过一个表单更新多个模型
查看文件:
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');
Controller文件:
$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;
}
http://stackoverflow.com/questions/14831307/how-to-insert-multiple-records/14831717#14831717 – 2013-02-26 12:08:38
这是代码插入数据库..我想更新字段,而不是添加... – Vicky 2013-02-26 12:11:06
它不是在cakephp中的主要区别只是读取数据和通过身份证在隐藏然后cakephp会为你做更新...我看不到隐藏的ID创建你的 – 2013-02-26 12:12:29