简体   繁体   中英

Update DB field using Zend Framework

I'm a n00bie with Zend but I'm learning it. I want to update a field in the database using a button, but I don't know how to do it.

This is what I wanna do: UPDATE $table SET content_field=1 WHERE $id = contentId

For example if I press that button I wanna put a 1 in the field instead of a default 0.

Assuming you have a Client table and created the model

$model_client = new Model_Client();
$client = $model_client->find($my_client_row_id)->current();
$client->some_field = 1;
$client->save();

You can do an update query with this code

$db = Zend_Db_Table::getDefaultAdapter();
$table = new Application_Model_DbTable_TableName();
$where = $table->getAdapter()->quoteInto('id = ?', $contentId);
$data = array('content_field' => 1);
$table->update($data, $where);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM