Model Custom Attribute with setAttribute()

I am having few custom attributes in my model. It is behaving in strange way. have a look at my use cases:


$customAttr = ''; // This is custom Attribute in Model

If I do:


$model->setAttribute('customAttr', 'Avinash');

In this case field value is not populated in ActiveForm.

If I do:


$model->customAttr = 'Avinash';

In this case field value populated in ActiveForm

Anything wrong I am doing?

You are doing it right -> http://www.yiiframework.com/doc-2.0/yii-base-component.html#__set()-detail

So my question is, what’s wrong with setAttribute so it does not populate ActiveForm field?