Prior to the ThinkPHP3.1 version, if you need to set up automatic validation or auto-completion, in general must be defined in the model, or through the SetProperty method to dynamically set the properties to complete, the disadvantage is that it is not easy 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 action:
$validate = Array ( ' verify ', ' Require ', ' captcha must! '), Array (' name ', ' ', ' account name already exists! ', 0, ' unique ', 1), $auto = 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.