views:

29

answers:

2

Hello friends.

Is there something similar to save for the update task?

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

$data_from_post = $_POST;
$newUser = $usersDb->fetchNew();
$newUser->setFromArray($data_from_post);
$newUser->save();

Is there something for the update task?

Thanks and best regard´s.

A: 
$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

Iznogood
Thanks for your help, I had founded here two great ways to do what I want. Best regard´s.
Rodrigo Ferrari
A: 

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();

Inkspeak
Wow, great one, I will try to do it! And can I save an object? Thanks.
Rodrigo Ferrari
Sure, that's what you're doing in your same $newUser->save();.
Inkspeak