single table inheritance switch views

I am implementing STI as in http://www.yiiframework.com/wiki/198/single-table-inheritance/

the wiki page talks about cars, so I will do so.

I want to list cars from all types. each type has its own view file.

currently I use switch to decide the correct view file.


		$Cars = Car::model()->findAll();

		foreach($Cars as $car)

		{

			switch ($car->type){

        	case "sport":

        	  $this->render('sport-view',array($car));

        	case "family":

        	  $this->render('family-view',array($car));

        	case "tatata":

        	  $this->render('tatata-view',array($car));

      }

I think this is very stupid.

anybody have any better approach.

okay you can mock me if you think you need to :)

How about:




$cars = Car::model()->findAll();

foreach( $cars as $car )

{

  $this->render( $car->type . '-view', array( $car ) );

}