How to do inheritance?

Is there a way to create inheritance in Yii?

I want to do the following:

  1. Create an abstract class called 'Media' that extends CActiveRecord,

  2. Create two subclasses, 'Video' and 'Photo'.

  3. Store all of the information in the same table with a column 'class' which records what class type a record is for.

  4. Make Yii automatically return Active Records cast as objects of the correct class.

Is this possible with Yii? If not, how can I achieve something similar?


I just added a method named CActiveRecord::instantiate().

You can override this method in Media. The method should create either a Video or a Photo object depending on the 'class' value given in the method parameter.

Now, if you do Media::model()->findAll(), the returned array will contain video and photo objects, according the 'class' column value.

Wow, thanks!

I am very impressed with Yii so far…  ;D