源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Yii数据模型中rules类验证器用法分析

  • 时间:2021-10-15 16:56 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/386.htm]Yii框架入门及常用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/155.htm]php优秀开发框架总结[/url]》、《[url=http://www.1sucai.cn/Special/26.htm]smarty模板入门基础教程[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部