2011-12-06 57 views
0

我無法更新我的表中的條目。我使用的代碼如下:Zend db table - save()not saving

class Model_Notification extends Zend_Db_Table_Abstract 
{ 
    protected $_name = "notifications"; 
    public function encrypt($id,$key) 
    { 
     $select = $this->select(); 
     $select->where('id = ?', $id); 
     $row = $this->fetchRow($select); 

     if($row) 
     { 
      $row->key = $key; 
      $row->save(); 
      return true; 
     } 
     return false; 

    } 
} 

起初,我想這可能是列名「關鍵」,所以我改成了「萬能鑰匙」,但沒有成功。每當我真正回到我身邊!

我仍然可以添加/刪除表格,但我明白了爲什麼這個更新save()不起作用!

乾杯,

回答

1

更優化的方式

$table = new Table(); 
$data = array(
    "field1" => "value1", 
    "field2" => "value2" 
); 
$where = $table->getAdapter()->quoteInto("id = ?",$id); 


$table->update($data, $where); 
+0

在哪裏,你如何獲得更新的表名? –

2

試試這個:

 
$data = array(
    "field1" => "value1", 
    "field2" => "value2" 
); 
$where = "id = " . $id; 

$table = new Table(); 
$table->update($data, $where);