Yii資料模型中rules類驗證器用法分析_php執行個體

來源:互聯網
上載者:User

本文執行個體講述了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: Regex驗證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相關內容感興趣的讀者可查看本站專題:《Yii架構入門及常用技巧總結》、《php優秀開發架構總結》、《smarty模板入門基礎教程》、《php物件導向程式設計入門教程》、《php字串(string)用法總結》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》

希望本文所述對大家基於Yii架構的PHP程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.