[英]DBTable creates new row instead off updating the existing
我嘗試使用現在的數據更新數據庫條目,但是我只是創建一個新條目:
$client =$this->clientTable->find($id);
$client->CompanyName = $request->getPost('CompanyName');
$this->clientTable->update();
$this->_redirect('client/index');
Zend_Db_Table_Abstract :: find()方法返回Zend_Db_Table_Rowset對象 。 您應該使用將返回Zend_Db_Table_Row對象並使用它的方法。
例如:
$clientRow = $this->clientTable->fetchRow(array('id' => $id));
$clientRow->CompanyName = $request->getPost('CompanyName');
$clientRow->save();
如果您的表主鍵名稱不是' id ',請在上面的第一行代碼中將其更改為合適的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.