ThinkPHP automatic verification, automatic addition, and form error analysis, thinkphp form

Source: Internet
Author: User

ThinkPHP automatic verification, automatic addition, and form error analysis, thinkphp form

This article describes thinkPHP automatic verification, automatic addition, and form errors. We will share this with you for your reference. The details are as follows:

I recently made another project and wanted to use thinkphp for verification. The result was a few days in tears. At the beginning, it was a token error. What Automatic addition later was invalid.

I have been testing and searching. I know that the create () method originally has two parameters,

The first parameter is the data parameter, and the second parameter is the hidden $ type parameter. What is this parameter used to control ??
Copy codeThe Code is as follows: // $ type = $ type? $ Type! Empty ($ data [$ this-> getPk ()])? Self: MODEL_UPDATE: self: MODEL_INSERT );

After carefully pondering this sentence, we found that this hidden parameter is used to indicate the specific operation of the database?

If the value of $ type is 1, it is an insert operation. If the value is 0, it is an update operation. By default, you do not need to assign a value to this parameter because the system can automatically identify this parameter.

If your primary key is automatically added to the database, it will be okay. If it is manually added, it will be a tragedy. This is because data update is performed by default.

The following is the automatically completed code I wrote.

protected $_auto = array(array('password','sha1',1,'function'),array('date', 'time', 1, 'function'),);

If the value of 1 does not exist, the value of 1 indicates that the function is executed only when data is inserted. PS: It's because of this that I have struggled for a long time.

When you want to input data, you can write as follows:

Create ($ _ POST, 1) // [insert data] create ($ _ POST, 2) // [update data]

Directly tell the create method that this operation is an insert operation, which can solve the problem of incorrect Automatic completion time and invalid Automatic completion.

But you insist on not writing this way, and I can't do it either. You just need to remember that if the create () function is used, the data is updated by default. When writing the Model method.

Automatic thinkphp completion Graph

No,

Protected $ _ auto = array ('Password', 'sha1', 2, 'function'), array ('date', 'time', 2, 'function'), // replace 1 with 2 .);

The problem can be solved.

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.