Home >Backend Development >PHP Tutorial >Introduction to the new features of ThinkPHP3.1, dynamic setting automatic completion and automatic verification
This article mainly introduces the dynamic setting automatic completion and automatic verification functions of ThinkPHP3.1. Friends who need it can refer to it
Before the ThinkPHP3.1 version, if you need to set automatic verification or automatic completion, It must be defined in the model, or the property can be dynamically set through the setProperty method, but the disadvantage of this is that it is not convenient for dynamic changes and adjustments.
ThinkPHP3.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. The sample code is as follows:
$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 can also support function calls (due to limitations of PHP itself , functions cannot be called in class attribute definitions).
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.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Introduction to multi-layer MVC support in the new features of ThinkPHP3.1
##ThinkPHP3.1 new Features provide a more complete introduction to Ajax support
The above is the detailed content of Introduction to the new features of ThinkPHP3.1, dynamic setting automatic completion and automatic verification. For more information, please follow other related articles on the PHP Chinese website!