Yii-資料模型- rules類驗證器方法詳解,yii-rules_PHP教程

來源:互聯網
上載者:User

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: 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 rules 規則 自訂寫法

yxmhero1989.blog.163.com/...61864/
 

yii中的controller怎調用model自訂的方法

一般情況下使用的是 Model::model()->方法名
 

http://www.bkjia.com/PHPjc/867538.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/867538.htmlTechArticleYii-資料模型- rules類驗證器方法詳解,yii-rules public function rules() { return array( array('project_id, type_id, status_id, owner_id, requester_id,', 'numerical', 'i...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.