設置一個修改方法,但是save(),沒有成功,數據修改失敗,查了好久,一般情況就是不符合rules規則,而我沒有設置rules規則,重新設置了一個不能為空,然后就修改成功,rules里面什么也不寫,也不行!具體還在學習中!先找了找rules一般驗證需要的!required : 必須值驗證屬性[['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #說明:CRequiredValidator 的別名, 確保了特性不為空. email : 郵箱驗證['email', 'email']; #說明:CEmailValidator的別名,確保了特性的值是一個有效的電郵地址. match : 正則驗證[['字段名'],match,'pattern'=>'正則表達式','message'=>'提示信息']; [['字段名'],match,'not'=>ture,'pattern'=>'正則表達式','message'=>'提示信息']; /*正則取反*/ #說明:CRegularExpressionValidator 的別名, 確保了特性匹配一個正則表達式. url : 網址['website', 'url', 'defaultScheme' => 'http']; #說明:CUrlValidator 的別名, 確保了特性是一個有效的路徑. captcha : 驗證碼['verificationCode', 'captcha']; #說明:CCaptchaValidator 的別名,確保了特性的值等于 CAPTCHA 顯示出來的驗證碼. safe : 安全['description', 'safe'];compare : 比較['age', 'compare', 'compareValue' => 30, 'operator' => '>=']; #說明:compareValue(比較常量值) - operator(比較操作符) #說明:CCompareValidator 的別名,確保了特性的值等于另一個特性或常量. default : 默認值['age', 'default', 'value' => null]; #說明:CDefaultValueValidator 的別名, 為特性指派了一個默認值. exist : 存在['username', 'exist']; #說明:CExistValidator 的別名,確保屬性值存在于指定的數據表字段中. file : 文件['primaryImage', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024]; #說明:CFileValidator 的別名, 確保了特性包含了一個上傳文件的名稱. filter : 濾鏡[['username', 'email'], 'filter', 'filter' => 'trim', 'skipOnArray' => true]; #說明:CFilterValidator 的別名, 使用一個filter轉換屬性. in : 范圍['level', 'in', 'range' => [1, 2, 3]]; #說明:CRangeValidator 的別名,確保了特性出現在一個預訂的值列表里. unique : 唯一性['username', 'unique'] #說明:CUniqueValidator 的別名,確保了特性在數據表字段中是唯一的. integer : 整數['age', 'integer'];number : 數字['salary', 'number'];double : 雙精度浮點型['salary', 'double'];date : 日期[['from', 'to'], 'date'];string : 字符串['username', 'string', 'length' => [4, 24]];boolean : 是否為一個布爾值['字段名', 'boolean', 'trueValue' => true, 'falseValue' => false, 'strict' => true]; #說明:CBooleanValidator 的別名 原文鏈接http://www.yiichina.com/tutorial/635
?