嘿傢伙請幫我在這我想更新兩個表的數據通過一個單一的表格,但數據更新只在一個表中,並插入第二個表中,而不是更新現有的記錄。這裏是我的代碼 -通過一個表單更新多個模型
查看文件:
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