Yii model rules使用

今天使用model rules 里面的 on 发现死活不起作用,后来搜索发现 需要设置model 实例的 scenario 属性才能起作用,不知道为什么。

 

//控制器内	

$model = new User();
$model->scenario = 'add'; //模型内 public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('username, password', 'required','message'=>'不能为空','on'=>'add'), array('username, password, salt, email', 'length', 'max'=>128), //array('profile', 'safe'), array('password_re','compare','compareAttribute'=>'password','message'=>'密码必须一致!','on'=>'add'), array('username','unique','message'=>'用户名已存在'), //array('addtime','default','value'=>time()), //array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()), ); }

  

posted @ 2014-03-20 17:41  My Game  阅读(489)  评论(0编辑  收藏  举报