DBTable 创建新行而不是更新现有行


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",请在上面的第一行代码中将其更改为合适的值。