Cant get COMPARE to work

Hi folks, sorry for my next question ;(

But I trief to find the ansrer in the forums, on this website. But I cant get the compare validate to work…

Here is the model class:



<?php





class User extends CActiveRecord


{





    public $password_repeat;


    public $email1_repeat;


    public $tags;





    /**


     * Returns the static model of the specified AR class.


     * @return CActiveRecord the static model class


     */


    public static function model($className=__CLASS__)


    {


        return parent::model($className);


    }





    /**


     * @return string the associated database table name


     */


    public function tableName()


    {


        return 'User';


    }





    /**


     * @return array validation rules for model attributes.


     */


    public function rules()


    {


        return array(


            array('username','length','max'=>10, 'min'=>2),


            array('username', 'unique', 'caseSensitive' => 'false'),


            array('password','length','max'=>30),


            array('email1','length','max'=>30),


            array('email1', 'email'),


            array('username, password, email1', 'required'),


            array('username', 'unique'),


            array('password_repeat', 'required', 'on'=>'register'),


            array('password', 'compare', 'on'=>'register'),


        );


    }





    /**


     * @return array relational rules.


     */


    public function relations()


    {


        return array(


        );


    }





    /**


     * @return array customized attribute labels (name=>label)


     */


    public function attributeLabels()


    {


        return array(


            'username'=>'Username',


            'password'=>'Password',


            'email1'=>'Primary E-Mail',


            'id'=>'Id',


            'referral'=>'Referral',


            'uuid' => 'uuid',


            'password_repeat' => 'Repeated password'


        );


    }


}


Well and in the view i use password_repeat… I tested to set compareAttribute. But this doesnt help too ;(

It displays every time that I have to repeat the password…

Ups something went wrong before ^^

It will not work without compareAttribute. Did you try it this way?

<?php


array('password', 'compare', 'on'=>'register', 'compareAttribute'=>'password_repeat'),

Quote

Well and in the view i use password_repeat... I tested to set compareAttribute. But this doesnt help too ;(

Yes…

Ah, you don’t have a safeAttributes() method. As password_repeat is not in your database table it will not be considered safe by default. So if you do massive assignment with

$user->attributes=$_POST[‘User’]
password_repeat will not be assigned.

Ahhhhhhhh so the documentation is a bit strange: All public attributes will be considered safe…

Then you should change this information a bit ;)

Hmm, i think it's already in the guide:

Quote

By default, the method returns all public member variables as safe attributes for CFormModel, while it returns all table columns except the primary key as safe attributes for CActiveRecord.

Quote

Ah, you don't have a safeAttributes() method. As password_repeat is not in your database table it will not be considered safe by default. So if you do massive assignment with
$user->attributes=$_POST['User']
password_repeat will not be assigned.

where do i have to write this code?

You have to declare a classvariable at the beginning of you user model. You can handle this variable like fileds of you database, lable, rules, and so on.