User model定义了两个字段 $passwordNew $passwordNew_repeat。
在rule中应用了array('passwordNew', 'compare')
在compare的validate中死活得不到 $passwordNew的值?为什么?
我尝试过添加safeAttribute方法也不行。
User model定义了两个字段 $passwordNew $passwordNew_repeat。
在rule中应用了array('passwordNew', 'compare')
在compare的validate中死活得不到 $passwordNew的值?为什么?
我尝试过添加safeAttribute方法也不行。
在验证前你试过$model->passwordNew么?
model->passwordNew是有值的,passwordNew不是持久值(也就是不是数据库字段)。
我把model->passwordNew值传递给了model->password,而且密码修改成功了。
但在CCompareValidate.php这个文件中,他执行到
if($this->allowEmpty && ($value===null || $value===''))就return了。
你是指在validator里$value为空么?这不大可能啊,因为$value=$model->$attribute。
我也想不通啊!CCompareValidator.php 我 userController 之间还有位置可以调试吗?
听说yii有safeAttribute的方法,但我一直没有用到,是不是这个原因。
我贴一下use的定义代码
class User extends CActiveRecord{ public $passwordNew; public $passwordNew_repeat;
首先你需要确定的是$model->attributes=$POST['ModelClass']后,$model->passwordNew是否确实有值(如果没有,说明你safeAttributes没有把 passwordNew列进去)。
怎么添加呢?是这样吗?确实没有导入到attributes里面去。
我这样添加不对吗?
public function safeAttributes(){
$attributes[]='passwordNew';
$attributes[]='passwordNew_repeat';
}
$attributes=parent::safeAttributes().
…
或者直接return array(…)