Home > Backend Development > PHP Tutorial > ThinkPHP3.1 new features: dynamic setting auto-completion and automatic verification examples_PHP tutorial

ThinkPHP3.1 new features: dynamic setting auto-completion and automatic verification examples_PHP tutorial

WBOY
Release: 2016-07-13 10:24:39
Original
814 people have browsed it

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();

Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825365.htmlTechArticleIn the past, before ThinkPHP3.1 version, if you need to set up automatic verification or automatic completion, generally speaking, it must be defined in the model , or dynamically set properties through the setProperty method,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template