CakePHP Update data (reprint)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.