Introduction of auto-completion and automatic verification of ThinkPHP3.1 new features dynamic setting

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.