Thinkphp automatic verification and automatic filling are invalid solutions. Automatic verification and auto-filling are frequently used when thinkphp is used, but sometimes automatic verification and auto-filling do not work, in this article, thinkphp's automatic verification and automatic self-validation and automatic filling are often used when thinkphp is used, but sometimes the automatic verification and automatic filling do not work, this article analyzes the possible causes of thinkphp automatic verification and auto-filling failure and proposes corresponding solutions.
(1) there is a problem with the create () method
ThinkPHP automatic verification and automatic filling are implemented when the data object create () is created, so automatic verification and automatic filling are largely related to create.
The create method syntax is as follows:
Create (mixed data, string type)
Data indicates the accepted data, and 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, and type is automatically recognized by the system by default.
However, the system automatically identifies type as a defect. when the input field has a primary key field, the system recognizes it as an update operation. Otherwise, it indicates a write operation. Therefore, when the primary key field is not automatically increased but needs to be written into SQL, 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, automatic verification and filling set below will be skipped:
Protected $ _ validate = array (
// Unique verification title when added
Array ('title', '', 'the title already exists! ', 0, 'Unique', 1 ),
};
// Automatic filling
Protected $ _ auto = array (
// Fill in the timestamp when adding the object
Array ('pubtime', 'time', 1, 'Function '),
);
Although the add () operation is performed to write data to the data table, 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), telling the system that this operation is writing data. In addition, if the input data is not $ _ POST, you must also pass the data as a parameter, such as create ($ _ GET ).
(2) the data field does not match
Due to carelessness, the form fields and data table fields are not properly matched.
(3) the data table fields have 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 and is unset. Therefore, after the table field name is changed, clear the Data table cache in Runtime/Data.
(4) incorrect Model name
The Model name is incorrect. it is not strictly named according to the specifications. for example, the first letter is not capitalized or careless, which leads to incorrect alphabetic order, many or fewer letters, etc. Such errors often cause model failure, especially in case sensitivity.
(5) No auto-increment id for the data table
When the data table does not have an auto-increment id, the data to be verified cannot be found during verification, so it will fail.
The above are several possible reasons for ThinkPHP's automatic verification and automatic filling failure. when a problem occurs, you must exclude it one by one. I believe you can find the error, of course, there are still some unknown errors. if you find another reason, please leave a message below to correct it.
Articles you may be interested in
- How to set automatic phpmyadmin login and cancel automatic login
- Php uses the filter function to verify the mailbox, url, and IP address
- PHP function for verifying that the ID card number is correct
- JavaScript, php regular expression verification for mixed numbers and letters (6-15 digits)
- Debugging methods required for using ThinkPHP
- How to set the jump wait time for the thinkphp page jump (successerror)
- Php extracts the birthday date from the ID card number and verifies whether it is a minor.
- Difference between execute and query methods in ThinkPHP
Token automatic verification and self...