_php instance of rules class validator usage analysis in YII data model

Source: Internet
Author: User
Tags smarty template yii

The examples in this article describe the usage of the Rules class validator in the Yii data model. Share to everyone for your reference, specific as follows:

Public Function rules () {return Array (' project_id, type_id, status_id, owner_id, requester_id, ', ' numerical ', ' integeronly ' =>true), Array (' name ', ' length ', ' Max ' =>256), array (' description ', ' Length ', ' Max ' =>2000) , Array (' create_time,create_user_id,update_user_id, update_time ', ' safe '), array (' ID, name, description, project_i
D, type_id, status_id, owner_id ', ' on ' => ' search '); //required: Required Array (' title,content ', ' required '),//match: Regular expression validation array (' Birthday ', ' match ', ' pattern ' => '%^\d{4} (\-|\/|\.) \d{1,2}\1\d{1,2}$% ', ' AllowEmpty ' =>true, ' message ' => ' birthday must be year-month-day format '),//email: Mailbox format Verification Array (' User_mail ', ' Email '),//url:url format verification Array (' User ', ' url '),//unique: Uniqueness Verification Array (' username ', ' unique ', ' casesensitive ' =>false, ' ClassName ' => ' user ', ' message ' => ' username ' {value} ' has been registered, replace '),//casesensitive define case sensitivity//compare: Consistency validation Array (' Repassword ', ' compare ', ' compareattribute ' => ' password ', ' message ' => ' two passwords not identical '),//length: Length validation//in: Verifying this genusThe sex value is in the list (specified by range).
Numerical: Verify that the value of this property is a numeric//captcha: Verify the property value and the consistent array (' Verifycode ', ' captcha ') displayed in the CAPTCHA,//type: Verify that the type of the property is the type specified by the. File: Verify that a property receives a valid upload file//default: property to specify a default value//exist: Verify that the property value exists in the database//boolean: Validate the Boolean property value//date: Verify that this property describes a date,
Time or DateTime//safe: Property flags are safe for batch assignment.

 Unsafe: Flags are unsafe, so they cannot be assigned in batches.

For more information on YII-related content, readers who are interested in this site can view the topics: Introduction to YII Framework and summary of common skills, "Summary of PHP Excellent development framework", "Smarty Template Introductory Course", "Introduction to PHP object-oriented programming", "PHP string" Summary of Usage , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the YII framework.

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.