Php 密码确认不需要';不工作,未定义

Php 密码确认不需要';不工作,未定义,php,yii,Php,Yii,如标题所述。我收到了以下错误消息 Property "User.repeat_password" is not defined. 尽管我已经在我的用户模型中定义了它 class User extends CActiveRecord { public $repeat_password; /** * @return string the associated database table name */ public function tableNa

如标题所述。我收到了以下错误消息

Property "User.repeat_password" is not defined.
尽管我已经在我的用户模型中定义了它

class User extends CActiveRecord
{

    public $repeat_password;

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'sys_user';
    }


    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('password, repeat_password', 'required', 'on'=>'insert'),
            array('password, repeat_password', 'length', 'min'=>6, 'max'=>40),
            array('repeat_password', 'compare', 'compareAttribute'=>'password', 'on'=>'create'),

            array('username', 'length', 'max'=>10),
            array('isactive', 'safe'),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('userid, username, password, isactive, role', 'safe', 'on'=>'search'),
        );
    }
这是查看代码

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'variable-form',
    'htmlOptions'=>array(
        'role'=>'form',
    ),
    'enableAjaxValidation'=>false,
)); ?>

    ...

    <div class="form-group">
        <?php echo $form->labelEx($model,'password'); ?>
        <?php echo $form->passwordField($model,'password', array('class'=>'form-control input-sm')); ?>
        <?php echo $form->passwordField($model,'repeat_password', array('class'=>'form-control input-sm')); ?>
        <?php echo $form->error($model,'password'); ?>
    </div>

    ...


<?php $this->endWidget(); ?>

</div><!-- form -->

...
...

有什么问题吗?请帮忙,我是Yii的新手。我应该在数据库中添加新列吗?

这是因为您扩展了CActiveRecord。我认为在您的表sys\u user not exist列repeat\u password中。我如何理解您希望创建一个包含任何验证、字段和处理的表单。您需要创建自定义类并从中进行扩展。 我的表格示例:

class RegistrationForm extends CFormModel
{

/**
 * @var string
 */
public $password;

/**
 * @var string
 */
public $repeat_password;

/**
 * @inheritdoc
 */
public function rules()
{
    return array(
        array('password, repeat_password', 'required'),
        array('password', 'compare', 'compareAttribute' => 'repeat_password'),
    );
   }
} 
如何使用:

 // in controller 
    $form = new RegistrationForm();
    if (isset($_POST['RegistrationForm'])) {
        $form->attributes = $_POST['RegistrationForm'];
        $form->validate();
     }
    $this->render('registration', array('model' => $form));
    //in view
    ...
    <?php echo $form->passwordField($model,'password', array('class'=>'form-control input-sm')); ?>
    <?php echo $form->error($model,'password'); ?>
    <?php echo $form->passwordField($model,'repeat_password', array('class'=>'form-control input-sm')); ?>
    <?php echo $form->error($model,'repeat_password'); ?>
    <?php $this->endWidget(); ?>
//在控制器中
$form=新注册表单();
如果(isset($_POST['RegistrationForm'])){
$form->attributes=$\u POST['RegistrationForm'];
$form->validate();
}
$this->render('registration',array('model'=>$form));
//鉴于
...

您的规则似乎有误。你能检查一下吗?怎么了>?你能指给我看吗?我完全不知道:(我不知道更多关于yii的信息,但是你可以参考规则并在外面检查它-