The methods for updating data in cakephp include Savefield () and UpdateAll (), where the former is used to hold a single field, which is used to update multiple records.
Savefield (String $fieldName, String $fieldValue, $validate = False)
Savefield () needs to set the model ID ($this->modelname->id = $id) before calling. When you use this method, the $fieldName should contain only the field name, not the model name plus the field name.
For example, use Savefield to update the title of the submission Journal:
$this->post->savefield (' title ', ' a new title for a New Day ');
UpdateAll (array $fields, array $conditions)
UpdateAll () defines the updated record with the $conditions array, and the value of the field is updated as defined by the $fields.
For example, to confirm that a member has been established for more than 1 years, the following update statement might be used:
$this _year Date Strtotime ('-1 Year ')); $this->baker->updateAll ( arraytrue), array(' baker.created <= ' = "$this _year"));
$fields the >
data to receive the SQL expression. text data needs to be manually added to the quotation marks.
For example, change the status of a specific user's ticket:
$this->ticket->updateAll ( ' ticket.status ' = ' closed ' "), Array(' ticket.customer_id ' = 453));
Blog statement:
All the articles in this blog, in addition to the title "reproduced" In the words, all the rest of the articles are my original or in the review of the information after the completion of the reference to non-reproduced articles please indicate this statement. --Blog Park-pallee
CakePHP Update data (reprint)