how to change a model safe attributes in yii
Question
I have a CActiveRecord model, and I need to change safe attributes list in that model. I have defined the safeAttributes method inside my model, like the following :
public function safeAttributes()
{
return array(
'name, bio',
);
}
the problem is 'bio' is not being considered in my safe attribute assign. I tried to dump the model safeAttributeNames attribute in my model, and what I've got was completely different from what safeAttributes should return.
Am I doing this in the right way ?
cheers, Firas
Solution
Assuming that you are using Yii 1.0.x then that is the correct way to do it.
If you are using Yii 1.1.x then it's changed. Have another read of the documentation.
public function rules()
{
return array(
array('username, password', 'required'),
array('rememberMe', 'boolean'),
array('password', 'authenticate'),
array('something', 'safe'),
array('someOtherThing', 'unsafe'),
);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow