开发者

Zend Framework DB update

Is there something similar to save for the update task?

If I want to save a new record I just do it:

$data_from_po开发者_运维问答st = $_POST;

$newUser = $usersDb->fetchNew();

$newUser->setFromArray($data_from_post);

$newUser->save();

Is there something for the update task?

Thanks and best regard´s.


$where = $usersDb->getAdapter()->quoteInto('id = ?', data_from_post['id']);
$usersDb->update($data_from_post, $where);

Assuming you have a id field in your post array. Basically update takes two params. The update array and a where clause.

see Updating Rows in a Table in here


You want to use $newUser->save() but your $newUser needs to be propagated from a $usersDb->find($_POST['id']); instead of a fetchNew(). And, of course, you'll need to update the $newUser with the new values from $_POST after you've instantiated. The save() method checks for modified fields and routes to update() instead of insert();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜