Fields not listed in rules are not saved


why are fields who are not listed in the rules array not saved into my database?

example: Username is listed in the safeAttributes array but not in the rules array, when i fill in the form everthing is stored in my database except the field Username.


Are you using 1.1 (trunk)? If so, only fields listed in rules() can be massively assigned. safeAttributes() is removed in 1.1.

yes just downloaded a 1.1-dev version this week. so the safeAttributes method is doing nothing…

Only attributes listed in the rules method will be massively assigned? Hoc can i assign fields manualy?

Yes. If an attribute doesn’t need validation but you still want it to be massively assigned, you can use the ‘safe’ validator:

array('username', 'safe'),

awesome i start to love yii :).

but how can i assign them manually like if an user update his details but not his password. so the password will be blank and have to be ignored by the AR during a update action.

This is not exactly manual assigning per se. This very specific use case has been described many times before, please use the search function to find the right answer.

Manual assigning, however, is simple:

$model->attribute = $value;