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教程之异常处理详解

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In C/C++, the pointer comparison rules are as follows: pointers pointing to the same object are equal. Pointers to different objects are not equal. Exception: Pointers to null addresses are equal.

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

As a very popular scripting language, PHP has powerful function library support. Its function naming conventions and rules have an important impact on development efficiency and code readability. This article will introduce the naming conventions and rules of PHP functions. 1. Naming style In PHP, function names need to strictly comply with naming specifications and rules. The specifications mainly include two aspects: naming style and naming rules. 1. Underline nomenclature Underline nomenclature is the most commonly used way to name PHP functions and is also an officially recommended way. Function names that follow this pattern

If you're asking "What is Yii?" check out my previous tutorial: Introduction to the Yii Framework, which reviews the benefits of Yii and outlines what's new in Yii 2.0, released in October 2014. Hmm> In this Programming with Yii2 series, I will guide readers in using the Yii2PHP framework. In today's tutorial, I will share with you how to leverage Yii's console functionality to run cron jobs. In the past, I've used wget - a web-accessible URL - in a cron job to run my background tasks. This raises security concerns and has some performance issues. While I discussed some ways to mitigate the risk in our Security for Startup series, I had hoped to transition to console-driven commands
