


Detailed explanation of thinkPHP automatic verification, automatic addition and form error issues
This article mainly introduces the analysis of thinkPHP automatic verification, automatic addition and form error problems, and analyzes the related usage skills and precautions of thinkPHP automatic completion mechanism in the form of a case. Friends in need can refer to it
I recently worked on another project and wanted to use thinkphp to write verification, but I cried for a few days. It was a token error at the beginning, and then something automatically added became invalid.
I have been testing and searching, and I found that the create() method originally had two parameters.
The first parameter is the data parameter that everyone knows, and the second parameter It is the hidden $type parameter. What is this parameter used to control? ?
Copy code The code is as follows:
//$type = $type?$type!empty($data[$this->getPk() ])?self::MODEL_UPDATE:self::MODEL_INSERT);
After thinking about this sentence carefully, I discovered that this hidden parameter is used to indicate the specific operation of this database?
$type takes a value of 1 for an insertion operation and 0 for an update operation. By default, there is no need to assign a value to this parameter because the system can automatically identify it.
If your primary key is automatically added by the database, then it will be fine. If you add it manually, it would be a tragedy. Because the default is to update data operation.
The following is the auto-complete code I wrote
protected $_auto = array( array('password','sha1',1,'function'), array('date', 'time', 1, 'function'), );
Do you see that 1? That 1 means that when data is inserted, Just execute the function. PS: It is because of this that I have been struggling for a long time.
When you want to enter data, you can write like this:
create($_POST,1)//【插入数据】 create($_POST,2)//【更新数据】
Directly tell the create method that this operation is an insertion operation, which can solve the problem The auto-complete timing is wrong and the auto-complete is invalid.
But if you insist not to write it like this, I can't help it. You just need to remember that if the create() function is used, the default is to update the data. When writing the Model method.
thinkphp auto-complete diagram
Do you see it?
protected $_auto = array( array('password','sha1',2,'function'), array('date', 'time', 2, 'function'), //把1换成2就好了。 );
The problem is It can be solved.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP determines whether a file exists in the specified directory
The above is the detailed content of Detailed explanation of thinkPHP automatic verification, automatic addition and form error issues. For more information, please follow other related articles on the PHP Chinese website!

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
