set value to field in model


I have a register form and this fields:

ID => autonumeric (system)

USERNAME => string (user) *required

PASSWORD => string (user) *required

EMAIL => string (user) *required

GROUP => integer (system)

in rules :

public function rules()


    return array(

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

        array('password', 'authenticate'),



My question is, how i can specify a value to GROUP field manually in yii model?


You can set it in controller, for example:

	$model->attributes = $_POST['MyFancyForm'];

	$model->group = 30;


nice, thanks dude

Another way: in your models you can use special function beforeSave

    protected function beforeSave()



          if ($this->isNewRecord)            

            $this->group = 30;

          return true;



            return false;