本文執行個體講述了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程式設計有所協助。