0

在注册表单中,使用了密码字段和确认密码字段。使用此数据后无法更新。模型

public function rules()
    {
            // NOTE: you should only define rules for those attributes that
            return array(
                    array('name, password', 'required'),
                    array('password', 'compare', 'compareAttribute'=>'confirm_password'), 
                    array('name', 'length', 'max'=>55),
                    // The following rule is used by search().
                    // Please remove those attributes that should not be searched.
                    array('id, name', 'safe', 'on'=>'search'),
            );
    }

尝试从 index.php 更新用户模型

`$post= User::model()->findByPk(1); $post->name='Abcdef'; $post->password='newpassword'; $post->save();`

新数据没有更新?什么时候解决?

4

2 回答 2

1

更新将不起作用,因为confirmpassword尚未设置。如果更新时不需要密码,请包含密码方案,否则将始终检查它。

     public function rules()
     {
        // NOTE: you should only define rules for those attributes that
        return array(
                array('name', 'required'),
                array('password', 'required','on'=>'create'),
                array('password', 'compare', 'compareAttribute'=>'confirmpassword','on'=>'create'),
                array('name', 'length', 'max'=>55),
                // The following rule is used by search().
                // Please remove those attributes that should not be searched.
                array('id, name', 'safe', 'on'=>'search'),
        );
于 2013-01-02T07:47:26.470 回答
-1
    public $confirmpassword;

    public function rules()
    {
            // NOTE: you should only define rules for those attributes that
            return array(
                    array('name, password, confirmpassword', 'required'),
                    array('password', 'compare', 'compareAttribute'=>'confirmpassword'), 
                    array('name', 'length', 'max'=>55),
                    // The following rule is used by search().
                    // Please remove those attributes that should not be searched.
                    array('id, name', 'safe', 'on'=>'search'),
            );
    }
于 2013-01-02T06:17:13.227 回答