I have an attribute that I want to be unsafe, so I made a rule declaring it as ‘unsafe’. When I run code that tries to change it, the attribute is NOT changed, however, there is also no error attached. I looked my Yii log and it states “Failed to set unsafe attribute…” but there was no error added to the model like other rules do.
Model code:
public function rules()
{
return array(
array('attributeName','unsafe');
);
}
I also took a look at the source code and saw no place where an error was being attached. However, according to the documentation there should be an error attached when it does not pass.
Thanks for you input CeBe, after reading that article I think I understand why ‘unsafe’ does not explicitly attach an error. Correct me if I am wrong but if it did attach errors then on almost any update where the entire object was given in the POST it would likely attach an error because you wouldn’t want the ID or Password field to be updated (if those were indeed in the body) but they had to be included for other reasons like perhaps security or something.