This article mainly introduces the dynamic setting auto-completion and auto-verification function of ThinkPHP3.1, the need of friends can refer to the following
Prior to the ThinkPHP3.1 version, if you need to set up automatic validation or auto-completion, you must either define it in the model or set the properties dynamically through the SetProperty method, but the disadvantage is that it is less convenient to dynamically change and adjust.
The ThinkPHP3.1 version adds auto and validate two consecutive operations to the model class to dynamically set auto-completion and automatic validation rules, which can now be used in the action, as shown in the following example code:
$validate = Array (verify,require, verification code must!) ), Array (name, the account name already exists!) , 0,unique,1), $auto = Array (Array ( password,md5,1,function), Array (create_time,time,2,function), ); M (User)->auto ($auto)->validate ($validate)->create ();
The specification of the $auto and $validate variables is consistent with the definition rules for the _auto and _validate properties of the model class, and can also support function calls (functions cannot be called in the class's property definition due to the limitations of PHP itself).
The auto and validate methods must be called before the Create method.
With this improvement, you can completely instantiate the model class with the M method and use dynamic settings to complete automatic validation and auto-completion, eliminating the need to rely on the D method.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!