Home >Backend Development >PHP Tutorial >ThinkPHP3.1 new features: dynamic setting auto-completion and automatic verification examples_PHP tutorial
In the past, before ThinkPHP version 3.1, if you needed to set up automatic verification or automatic completion, it generally had to be defined in the model, or completed by dynamically setting properties through the setProperty method. The disadvantage of this is that it is inconvenient to dynamically change and Adjustment.
ThinkPHP 3.1 version adds two coherent operations, auto and validate, to the model class, which are used to dynamically set auto-complete and auto-validation rules. They can now be used in Action:
$validate = array( array('verify','require','验证码必须!'), array('name','','帐号名称已经存在!',0,'unique',1), ); $auto = array ( array('password','md5',1,'function') , array('create_time','time',2,'function'), ); M('User')->auto($auto)->validate($validate)->create();
The specifications of $auto and $validate variables are consistent with the definition rules of the _auto and _validate attributes of the model class, and they can also support function calls (due to limitations of PHP itself, functions cannot be called in the attribute definition of the class) .
The auto and validate methods must be called before the create method.
Through this improvement, you can instantiate the model class through the M method and then use dynamic settings to complete automatic verification and automatic completion operations. You no longer have to rely on the D method.