CActiveRecord add to database with less code

Howdy everyone, is there a more concise way to write the following:




$user = new User;

$user->user_id = Yii::app()->user->id;

$user->email = $email;

$user->codename = $codename;

$user->save();



Is there a way to set multiple variables in 1 line or any other way to condense this code that you guys can think of?

Cheers.




$user = new User;

$user->attributes = ['user_id' => Yii::app()->user->id, 'email' => $email, 'codename' => $codename];

$user->save();



But it is not just the same thing, because attributes that are not in validation rules, they are skipped.

Does this mean that any value I pass in through an array like this must have at least 1 validation rule?

Exactly, or it is enought that attributes are in ‘safe’ validator.

I understand, thank you for your quality answer.

Also, I’ll add think link on safe validation rules for anyone else with a similar curiosity:

http://www.yiiframework.com/wiki/161/understanding-safe-validation-rules/