Component direct()

Not sure if there is support for this already, but it would be great if components had a direct() method:

<?php


$user = Yii::app()->loadModel('User');


?>

Would call:

<?php


class LoadModel extends CApplicationComponent


{


    public function direct($modelName)


    {


        return call_user_func_array($modelName.'::model', array($modelName));


    }


}


?>

By the way, to those wondering why I would do this above… I simply dont want to have to add static model() methods in EACH of my models.

Could you explain how this would simplify your code?

Isn't this equivalent to

$user=User::model();

No, because in order to call User::model() and get back a User instance you need to define the static model() function within User.php because PHP can’t handle static inheritance (http://socket7.net/a…and-inheritance).  Therefore I would have to define this following method within ALL model classes;

<?php


class User extends CActiveRecord


{


    public static function model($className = __CLASS__)


    {


        return parent::model($className);


    }


}





class Post extends CActiveRecord


{


    public static function model($className = __CLASS__)


    {


        return parent::model($className);


    }


}


?>

I don't like to repeat myself, so that's why I created the component.  You might come back and say why not just do:

<?php


$user = CActiveRecord::model('User');


?>

But, I don't want to have to bother knowing which of my models are of type CActiveRecord or CModel (like CFormModel instance) or heck, even if a model is a plain old object.