search
Homephp教程php手册Yii rules常用规则示例,yiirules示例

Yii rules常用规则示例,yiirules示例

本文讲述了Yii rules常用规则。分享给大家供大家参考,具体如下:

public function rules()
{
  return array(
    //必须填写
    array('email, username, password,agree,verifyPassword,verifyCode', 'required'),
    //检查用户名是否重复
    array('email','unique','message'=>'用户名已占用'),
    //用户输入最大的字符限制
    array('email, username', 'length', 'max'=>64),
    //限制用户最小长度和最大长度
    array('username', 'length', 'max'=>7, 'min'=>2, 'tooLong'=>'用户名请输入长度为4-14个字符', 'tooShort'=>'用户名请输入长度为2-7个字'),
    //限制密码最小长度和最大长度
    array('password', 'length', 'max'=>22, 'min'=>6, 'tooLong'=>'密码请输入长度为6-22位字符', 'tooShort'=>'密码请输入长度为6-22位字符'),
    //判断用户输入的是否是邮件
    array('email','email','message'=>'邮箱格式错误'),
    //检查用户输入的密码是否是一样的
    array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message'=>'请再输入确认密码'),
    //检查用户是否同意协议条款
    array('agree', 'required', 'requiredValue'=>true,'message'=>'请确认是否同意隐私权协议条款'),
    //判断是否是日期格式
    array('created', 'date', 'format'=>'yyyy/MM/dd/ HH:mm:ss'),
    //判断是否包含输入的字符
    array('superuser', 'in', 'range' => array(0, 1)),
    //正则验证器:
    array('name','match','pattern'=>'/^[a-z0-9\-_]+$/'),
    //数字验证器:
    array('id', 'numerical', 'min'=>1, 'max'=>10, 'integerOnly'=>true),
    //类型验证 integer,float,string,array,date,time,datetime
    array('created', 'type', 'datetime'),
    //文件验证:
    array('filename', 'file', 'allowEmpty'=>true, 'types'=>'zip, rar, xls, pdf, ppt','tooLarge'=>'图片不要超过800K'),
       array('url',
        'file',  //定义为file类型
        'allowEmpty'=>true,
        'types'=>'jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx',  //上传文件的类型
        'maxSize'=>1024*1024*10,  //上传大小限制,注意不是php.ini中的上传文件大小
        'tooLarge'=>'文件大于10M,上传失败!请上传小于10M的文件!'
    ),
 });
$news= new news('search'); //search关联规则

转自: 小谈博客 http://www.tantengvip.com/2015/05/yii-rules/

更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • PHP YII框架开发小技巧之模型(models)中rules自定义验证规则
  • Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例
  • 使用Composer安装Yii框架的方法
  • Yii使用migrate命令执行sql语句的方法
  • YII Framework框架使用YIIC快速创建YII应用之migrate用法实例详解
  • YII Framework框架教程之使用YIIC快速创建YII应用详解
  • YII Framework框架教程之国际化实现方法
  • YII Framework框架教程之缓存用法详解
  • YII Framework框架教程之安全方案详解
  • YII Framework框架教程之日志用法详解
  • YII Framework教程之异常处理详解
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

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.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)