Auto-validation and auto-fill are often used when using thinkphp, but occasionally when automatic validation and autofill do not work, this article analyzes the possible causes of thinkphp auto-validation and auto-fill invalidation, and proposes corresponding solutions.
(1) There is a problem with the Create () method
thinkphp automatic validation and AutoFill are implemented when creating a data object Create (), so automatic validation is largely related to create ().
The Create method syntax is as follows:
Create (mixed data, String type)
Data represents the accepted information, and the type represents the specific operation (write or update data) for this time. Two parameters can be omitted, the data parameter is omitted by default to accept $_post, and type is automatically recognized by the system by default.
However, the system automatically recognizes that the type is defective, and when the incoming field has a primary key field, the system is recognized as an update operation, otherwise it is a write operation. Therefore, automatic validation and auto-population may not be valid when primary key fields are not autogrow but require SQL writes.
For example, when adding data records, if the form has a primary key field or the system has a primary key field (such as input device number), then thinkphp think this operation is an update operation, for example, the following set of automatic validation and padding will be skipped:
Protected $_validate = Array (
Verify header unique when new
Array (' title ', ' ', ' title already exists! ', 0, ' unique ', 1),
};
Auto Fill
Protected $_auto = Array (
Fill timestamp when new
Array (' Pubtime ', ' time ', 1, ' function '),
);
Although the Add () operation was performed in the operation, the data was written to the data table, but the automatic validation and autofill were found to be invalid.
When this occurs, simply pass the action type explicitly to the Create () method, which is create ($_post,1), which tells the system that this operation is writing data. Also, if the incoming data is not $_post, pass the data as a parameter, such as Create ($_get).
(2) Data fields do not correspond
Due to carelessness, there are no good form fields and data table fields.
(3) The Data table field is changed
During the development process, the name of the table field was changed, and the cache was not updated in time, causing the system to be judged as invalid field and unset out. Therefore, after changing the name of the table field, the data table cache under Runtime/data is purged in time.
(4) Model naming error
Model naming error, not strictly according to the specification, such as the first letter is not uppercase or careless result in alphabetical order, more or less letters and so on. Such errors tend to lead directly to the failure of the model, which is particularly important to note in this case.
(5) Data Sheet no self-increment ID
When there is no self-increment ID in the data table, the data that needs to be verified is not found, so it fails.
The above is the thinkphp automatic verification and auto-fill invalid may occur several reasons, when the problem to be one to exclude, I believe you can find the wrong, of course, there are some unknown errors, if you find another reason, please leave a comment below.
Articles you may be interested in
- How to set phpMyAdmin automatic login and cancel auto sign-in
- Php method for verifying mailboxes, URLs, and IP addresses using the filter function
- A function that PHP verifies that the ID number is correct
- js,php regular validation is a mix of numbers and letters (6-15-bit)
- Debugging methods that must be mastered using thinkphp
- thinkphp page Jump (successerror) How to set the jump wait time
- PHP Extract the birthday date from the ID number and the function to verify whether it is a minor
- The difference between execute and query methods in thinkphp
http://www.bkjia.com/PHPjc/764121.html www.bkjia.com true http://www.bkjia.com/PHPjc/764121.html techarticle Auto-validation and AutoFill are features that are often used when using thinkphp, but occasionally come across situations where automatic validation and autofill do not work, and this article thinkphp automatic validation with self ...