Now I am working with the yii framework, and I would like to write something like this:
protected static $model = "Customer";
...
public function actionIndex() {
$model::model()->find(...
Now it works:
protected static $model = "Customer";
protected static $model_obj;
...
public function __construct($controller, $id) {
$this->model_obj = new self::$model;
...
public function actionIndex() {
$model_obj::model()->find(...
but creating an object to access a static member is bad. how to avoid it?
getClass takes an object as the first parameter and is not suitable for this purpose
google say:
$a = constant($myClassName . "::CONSTANT");
$b = call_user_func(array($myClassName, "static_method"));
it looks like a terrible world of crap. using this can cause many problems. another solution?
about! my problem was different:
$controller::$NAME::model()
$controller_name = $controller::$NAME
$controller_name::model()
thank
puchu source
share