ThinkPHP3.1 new features Dynamic Setup Auto-complete and auto-validate example _php instance

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

  • 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.