2011-05-12 58 views
2

嗨,我想创建一个“预订确认”链接,当点击时从0表中的字段“证实”变为1更新CakePHP的一个单一的数据库字段 - 应该是简单

所以远我有:

function admin_markAsConfirmed($id = null) { 
    $this - > Booking - > id = $id; 
    if ($this - > Booking - > saveField('confirmed', 1)) { 
     $this - > Session - > setFlash('Booking Confirmed'); 
     $this - > redirect(array('action' = > 'admin_index')); 
    } 
} 

但它不工作。所有这些都是插入一个新行,而不是编辑由$ id指定的行。

我该如何做这项工作?这似乎很简单,但我一直坚持这几个小时。

+3

你检查是否ID实际上正在设置? – JohnP 2011-05-12 08:20:52

回答

1

你应该使用这样的事情...

$this->Post->id = 1;<br/> 
$this->Post->read();<br/> 
$this->Post->set('title', 'New title for the article');<br/> 
$this->Post->save(); 

这里是link的蛋糕在线预订

+0

如果'saveField'不起作用,那么这也不起作用。 – JJJ 2011-05-12 13:57:17

+0

不起作用:( – 2011-05-13 02:17:59

+1

添加$ this-> Article-> read();后$ this-> Booking-> id = $ id;我不认为设置id实际上会做任何事情,直到您调用find或一个读取方法 – 2011-05-13 12:09:59

0

试试这个:

// Update field to desired value 
$data = array('someModel' => array('id' => $this->someModel->id, 'someField' => 'someInfo')); 

// Save the changes 
$this->someModel->save($data, false, array('someField')); 
相关问题