search
Homephp教程php手册Yii-数据模型- rules类验证器方法详解,yii-rules

Yii-数据模型- 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: 标志为不安全,所以他们不能被批量赋值。

 

Yii rules 规则 自定义写法

yxmhero1989.blog.163.com/...61864/
 

yii中的controller怎调用model自定义的方法

一般情况下使用的是 Model::model()->方法名
 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor