How can an model attribute is modified after load method? (like the afterFind method)

I have an attribute of the model which should be modified after it’s loaded from the database.

I could extend the afterFind method, which could the convert the varchar value to a php array. So it works find.

But when the model is loaded I have no idea how to convert that varchar to the php array.

I have tried with rules but does not works:

[['languages'], 'each', 'rule' => ['string']],

or this one

[['languages'], 'safe'],

So this one works afterFind:

public function afterFind()


    $this->languages = $this->convertToPHPArray($this->languages);



By the way I have tried to extend the init or the __constructor method with this conversation, but no success, after load method the languages attribute is still a string instead of a php array.

If I understood your question, I think that you could use a property in the model:

public class Model {

      public function getLanguagesArray()


             return $this->convertToPHPArray($this->languages);



Then, use it:

$arr = $model->languagesArray;

Yes this is not a bad solution, but in this case I will have to manage at 2 place the languages attribute in my sourcode!