AR method that runs before returning data

When I’m retrieving data from an AR object, I want to dynamically create some attributes that are returned along with the data from the DB. I used the method afterFind() for this. This works fine but I recently noticed, it does not work when using $model->search(). I’ve tried all kind of other methods, but I couldn’t find one that works on all cases.

So which method could I use that is always executed when fetching data from an AR object?

How is the additional properties created… if you generate them from other data… you can define model getters for them…

The virtual attributes are created based upon existing attributes, for example, the URL’s of the corresponding images. This way, I can just get the thumbnail URL from the AR model when using gridview.

I’m not sure if I can use getters inside a gridview.

Why not… for example if you don’t have a field “url” in your table and you add a method like this to your model

public function getUrl()


   return $this->something . $this->somethingOther;


now you can use $model->url in your code to get that "concatenaded" value…

Well it should work, I’ll try it :)