


Thinkphp automatic verification and automatic filling invalid solution_PHP tutorial
Automatic verification and autofilling are functions that are often used when using thinkphp, but occasionally you encounter situations where automatic verification and autofilling do not work. This article explains how thinkphp's automatic verification and autofilling may not work. Do some analysis of the reasons and propose corresponding solutions.
(1) There is a problem with the create() method
ThinkPHP automatic verification and automatic filling are implemented when creating the data object create(), so the invalidation of automatic verification and automatic filling is largely related to create().
The create method syntax is as follows:
create(mixed data, string type)
data represents the accepted data, and type represents the specific operation of this time (write or update data). Both parameters can be omitted. If the data parameter is omitted, $_POST data will be accepted by default, while type is automatically recognized by the system by default.
But the system’s automatic recognition of type is flawed. When the incoming field has a primary key field, the system recognizes it as an update operation, otherwise it is a write operation. So when the primary key field does not grow automatically but requires SQL writing, then automatic validation and automatic filling may not be effective.
For example, when adding a data record, if there is a primary key field in the form or a primary key field is generated in the system (such as entering a device number), then ThinkPHP will consider this operation to be an update operation. For example, the automatic verification and filling set below Will all be skipped:
protected $_validate = array(
//Verify that the title is unique when adding a new one
array('title','','Title already exists!',0,'unique',1),
};
//Autofill
protected $_auto = array(
// Fill in the timestamp when adding new
array('pubtime','time',1,'function'),
);
Although during the operation, the add() operation was executed to write the data to the data table, you will find that the automatic verification and automatic filling are invalid.
When this happens, 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 to write data. In addition, if the incoming data is not $_POST, the data must also be passed in as a parameter, such as create($_GET).
(2) Data fields do not correspond
Due to carelessness, the form fields and data table fields were not properly matched.
(3) Data table fields have been changed
During the development process, the table field names were changed, but the cache was not updated in time, causing the system to judge the field as invalid and unset it. Therefore, after changing the table field name, clear the data table cache under Runtime/Data promptly.
(4) Model naming error
The Model is named incorrectly and is not named in strict accordance with the specifications. For example, the first letter is not capitalized or carelessness results in the wrong order of letters, too many or too few letters, etc. Such errors often directly lead to model failure, so special attention needs to be paid to capitalization.
(5) The data table has no self-increasing id
That is, when there is no auto-incremented ID in the data table, the data that needs to be verified will not be found during verification, so it will fail.
The above are several possible reasons why ThinkPHP's automatic verification and automatic filling are invalid. When problems occur, you must eliminate them one by one. I believe you will be able to find the errors. Of course, there are some unknown errors. If you find them For another reason, please leave a comment below.
Articles you may be interested in
- How to set up phpmyadmin to automatically log in and cancel automatic login
- How to use filter function in php to verify email, url and ip address
- PHP function to verify whether the ID number is correct
- js, php regular verification whether it is a mixture of numbers and letters (6-15 digits)
- Debugging that must be mastered when using ThinkPHP Method
- thinkphp page jump (successerror) how to set the jump waiting time
- php function to extract the birthday date in the ID number and verify whether it is a minor
- The difference between execute and query methods in ThinkPHP

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.
