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.