我正在做一個函數來更改用戶密碼。在用戶模型的內部我創建了三個變量,如下所示。規則中兩個變量之間的規則在Yii中不起作用
public $oldPassword;
public $newPassword;
public $repatePassword;
現在我需要比較newPassword和repare密碼在一起,我在模型中添加followinf規則。
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password', 'required'),
array('username', 'length', 'max'=>20),
array('password', 'length', 'max'=>255),
array('oldPassword', 'findPassword', 'on' => 'changePwd'),
//array('repatePassword','compare','compareAttribute'=>'newPassword', 'on'=>'changePwd'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, username, password', 'safe', 'on'=>'search'),
);
}
我有以下形式。
<div class="row">
<?php echo $form->labelEx($model,'Old Password'); ?>
<?php echo $form->passwordField($model,'oldPassword',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'oldPassword'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'New Password'); ?>
<?php echo $form->passwordField($model,'newPassword',array('maxlength'=>255)); ?>
<?php echo $form->error($model,'newPassword'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Repate Password'); ?>
<?php echo $form->passwordField($model,'repatePassword',array('maxlength'=>255)); ?>
<?php echo $form->error($model,'repatePassword'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Update'); ?>
</div>
現在,當我在兩個字段中正好放置相同的值時,它仍然給我說值不一樣。爲什麼是這樣?
顯示完整的'rules()'方法。 'newPassword'必須有自己的規則才能被聲明爲安全的並被分配給變量。 – 2014-09-22 19:09:47
編輯questipn – Steve 2014-09-22 19:18:54