Possible causes of invalid ThinkPHP automatic verification and automatic filling

Source: Internet
Author: User
Automatic verification and automatic filling are frequently used when ThinkPHP is used, but sometimes automatic verification and automatic filling are invalid, this article analyzes the possible causes of ThinkPHP automatic verification and automatic filling failure. Automatic verification and automatic filling are frequently used when ThinkPHP is used, but sometimes automatic verification and automatic filling are invalid. in this article, ThinkPHP
Analyze the possible causes of invalid automatic verification and filling.
Create ()

ThinkPHP automatic verification and automatic filling are performed in the create () data object ()
So automatic verification and auto-fill ineffective are largely related to create.

The create method syntax is as follows:




  1. Create (mixed data, string type)

Data indicates the accepted data, type
Indicates the specific operation (write or update data ). Both parameters can be omitted. if the data parameter is omitted, $ _ POST data is accepted by default, while type
By default, it is automatically recognized by the system.

However, the system automatically recognizes the type
It is flawed. when the input field has a primary key field, the system recognizes it as an update operation. Otherwise, it is a write operation. Therefore, when the primary key field does not automatically increase, you need SQL
When writing data, automatic verification and automatic filling may be invalid.

For example, when adding a data record, if the form contains a primary key field or the system generates a primary key field (for example, enter the device number ),
ThinkPHP considers this operation as an update operation. for example, the automatic verification and filling settings set below will be skipped:




  1. Protected $ _ validate = array (
  2. // Unique verification title when added
  3. Array ('title', '', 'the title already exists! ', 0, 'Unique', 1 ),
  4. };



  1. // Automatic filling
  2. Protected $ _ auto = array (
  3. // Fill in the timestamp when adding the object
  4. Array ('pubtime', 'time', 1, 'Function '),
  5. );

Although the add ()
The operation writes data to the data table. However, automatic verification and automatic filling are invalid.

In this case, you only need to explicitly pass the operation type into the create () method, that is
Create ($ _ POST, 1) tells the system that this operation is to write data. In addition, if the incoming data is not $ _ POST, you must also pass the data as a parameter, as shown in figure
Create ($ _ GET ).
Field not matched

Due to carelessness, the form fields and data table fields are not properly matched.
The data table field has been changed.

During the development process, the table field name is changed, but the cache is not updated in time. as a result, the system determines that the field is invalid.
Unset. Therefore, after the table field name is changed, clear the Data table cache in Runtime/Data.
Incorrect Model name

Model
Naming error: The name is not strictly named according to the specifications. for example, the first letter is not capitalized or careless, leading to incorrect alphabetic order, many or fewer letters, etc. Such errors often lead to model failure.
M
Use automatic verification and automatic completion in the method

Generally, when a model is instantiated using the M method, the user-defined model class cannot be instantiated, and automatic verification and completion functions cannot be used. Therefore, we recommend that you use
D method to instantiate the model class. If you must implement automatic verification or automatic completion in the M method, see automatic verification and filling when ThinkPHP uses the M method (without creating a model class).

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.