ThinkPHP3.1 new features: automatic completion and automatic verification of dynamic settings

Source: Internet
Author: User
If you need to set automatic verification or automatic completion before version 3.1, it is generally necessary to define it in the model or use the setProperty method to dynamically set attributes. The disadvantage is that it is not convenient to dynamically change and adjust attributes. However, version 3.1 adds two coherent operations: auto and validate in the model class, which are used to dynamically set automatic completion and automatic verification rules. Currently, they can be used in Action: Before version 3.1, if you need to set automatic verification or automatic completion, it must be defined in the model or set attributes dynamically using the setProperty method. The disadvantage is that it is not convenient to dynamically change and adjust attributes.
However, version 3.1 is added to the model class. Auto and validateTwo coherent operations are used to dynamically set automatic completion and automatic verification rules. now you can use the following operations in Action:
  1. $ Validate = array (
  2. Array ('verify ', 'require', 'verification code is required! '),
  3. Array ('name', '', 'account name already exists! ', 0, 'Unique', 1 ),
  4. );
  5. $ Auto = array (
  6. Array ('password', 'md5', 1, 'Function '),
  7. Array ('create _ time', 'time', 2, 'Function '),
  8. );
  9. M ('user')-> auto ($ auto)-> validate ($ validate)-> create ();
Copy the code where the $ auto and $ validate variables are consistent with the definition rules of the _ auto and _ validate attributes of the model class, and function calling is also supported (due to PHP restrictions, you cannot call a function in the attribute definition of a class ).
The auto and validate methods must be called before the create method.
With this improvement, you can use the M method to instantiate the model class and then use dynamic settings to complete automatic verification and operations without relying 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.