0

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.

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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

5 Comments

sorry for the stupid question, but can I link to the button? Just because with PHP, I usually do something like that: <form name="form1" method="post" action="testForm.php"> <input type="Submit" name="Submit1" value="Update"> </form> and in the PHP file I write the sql actions, but I still don't understand how can I link the button from my view to a real action.
If you want to enter in the method "updateDataAction" in the controller "User" you need to do the post to /user/updatedata and access the post data with $this->_request->getParam('INPUT_NAME_PARAM'); Is that what you meant?
I hard coded a form in view/content/myfile.tpl like this: <form method="post" action="/Admin/"/> <select name="content_field"> <option value=""></option> <option value="0">Yes</option> <option value="1">No</option> <input value="Go" type="submit" /> </form> But I don't know how to "link" that submit button to an Update DB field function like this one: UPDATE $table SET content_field=1 WHERE $id = contentId
You have to create a controller ( framework.zend.com/manual/en/zend.controller.quickstart.html ) with inside an action (framework.zend.com/manual/en/zend.controller.action.html ). Your form should then link to /namecontroller/nameaction and in the method of the action you have to get the posted value (content_field) and execute the code i posted above
Oh cool, thank you very much. I'll read up well the pages and hope to fix the problem. Thank you very much for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.