2019獨角獸企業重金招聘Python工程師標準>>>
Rules驗證規則:required : 必須值驗證屬性||CRequiredValidator 的別名, 確保了特性不為空.[['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息'];email : 郵箱驗證||CEmailValidator 的別名,確保了特性的值是一個有效的電郵地址.['email', 'email'];match : 正則驗證||CRegularExpressionValidator 的別名, 確保了特性匹配一個正則表達式.[['字段名'],'match','pattern'=>'正則表達式','message'=>'提示信息'];
[['字段名'],'match','not'=>ture,'pattern'=>'正則表達式','message'=>'提示信息']; /*正則取反*/url : 網址||CUrlValidator 的別名, 確保了特性是一個有效的路徑.['website', 'url', 'defaultScheme' => 'http'];
captcha(驗證碼)||CCaptchaValidator 的別名,確保了特性的值等于 CAPTCHA 顯示出來的驗證碼.['verificationCode', 'captcha'];
safe : 安全['description', 'safe'];
compare :(比較) CCompareValidator 的別名, 確保了特性的值等于另一個特性或常量.['password', 'compare']
//compareValue:比較常量值 operator:比較操作符
['age', 'compare', 'compareValue' => 30, 'operator' => '>=']; //age必須大于等于30 否則給出提示[['wallet_share_price'],'compare', 'compareAttribute' =>'wallet_price', 'operator' => '<=','message'=>'分享者的金額必須小于等于限定金額'],[['wallet_shares_price'],'compare', 'compareAttribute' =>'wallet_price', 'operator' => '<=','message'=>'被分享者的金額必須小于等于限定金額'], //兩個屬性之間進行比較filter 過濾 [['username', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true], //不是過濾空格 是過濾 sql注入default : 默認值||CDefaultValueValidator 的別名, 為特性指派了一個默認值.['age', 'default', 'value' => null];[['wallet_price'], 'default', 'value' => 1], 設置默認值exist : 存在||CExistValidator 的別名, 確保屬性值存在于指定的數據表字段中.['字段名', 'exist'];file : 文件||CFileValidator 的別名, 確保了特性包含了一個上傳文件的名稱.['primaryImage', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024]filter : 濾鏡||CFilterValidator 的別名, 使用一個filter轉換屬性.[['username', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true];in : 范圍||CRangeValidator 的別名, 確保了特性出現在一個預訂的值列表里.['level', 'in', 'range' => [1, 2, 3]];unique : 唯一性||CUniqueValidator 的別名, 確保了特性在數據表字段中是唯一的.['字段名', 'unique'][['wallet_name'], 'unique'], //在wallet_name 這一列是唯一的[['wallet_name'], 'unique', 'targetAttribute' => 'wallet_price'], // 在目標屬性 wallet_price 這一列是唯一的 不在wallet_name 這一列integer : 整數['age', 'integer'];number : 數字['salary', 'number'];double : 雙精度浮點型['salary', 'double'];date : (日期)[['from', 'to'], 'date'];string : 字符串['username', 'string', 'length' => [4, 24]];boolean : 是否為一個布爾值||CBooleanValidator 的別名['字段名', 'boolean', 'trueValue' => true, 'falseValue' => false, 'strict' => true];image :是否為有效的圖片文件['primaryImage', 'image', 'extensions' => 'png, jpg', 'minWidth' => 100, 'maxWidth' => 1000, 'minHeight' => 100, 'maxHeight' => 1000]trim 去除 兩端的空白符;
[['username', 'email'], 'trim'],