这篇文章主要介绍了Yii数据模型中rules类验证器用法,结合实例形式分析了rules类验证器的简单使用方法,代码注释中包含了相关方法的使用说明,需要的朋友可以参考下
本文实例讲述了Yii数据模型中rules类验证器用法。分享给大家供大家参考,具体如下:
public function rules() { return array( 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_id, type_id, status_id, owner_id', 'on'=>'search'), ); } //required: 必填 array('title,content','required'), //match: 正则表达式验证 array('birthday', 'match', 'pattern'=>'%^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$%', 'allowEmpty'=>true, 'message'=>'生日必须是年-月-日格式'), //email:邮箱格式验证 array('user_mail', 'email'), //url:URL格式验证 array('user', 'url'), //unique:唯一性验证 array('username', 'unique','caseSensitive'=>false,'className'=>'user','message'=>'用户名"{value}"已经被注册,请更换'), //caseSensitive 定义大小写是否敏感 //compare:一致性验证 array('repassword', 'compare', 'compareAttribute'=>'password','message'=>'两处输入的密码并不一致'), //length:长度验证 //in: 验证此属性值在列表之中(通过range指定)。 //numerical: 验证此属性的值是一个数字 //captcha: 验证属性值和验证码中显示的一致 array('verifyCode','captcha'), //type: 验证属性的类型是否为type所指定的类型. //file: 验证一个属性是否接收到一个有效的上传文件 //default: 属性指定默认值 //exist: 验证属性值在数据库中是否存在 //boolean: 验证布尔属性值 //date: 检验此属性是否描述了一个日期、时间或日期时间 //safe: 属性标志为在批量赋值时是安全的。 //unsafe: 标志为不安全,所以他们不能被批量赋值。
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
The above is the detailed content of About the usage of rules class validator in Yii data model. For more information, please follow other related articles on the PHP Chinese website!

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

The article discusses various methods for page redirection in PHP, focusing on the header() function and addressing common issues like "headers already sent" errors.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
