2

The question is quite straight forward, but I guess answer isn't.

I have following syntax in my Yii application:

$model=\models\common\Recipe::getTableSchema()->columns;

I want to have dynamic class name each time this whole controller function is called. Like

$DynamicClass=$_GET['classname'];

$model=\models\common\$DynamicClass::getTableSchema()->columns;

But that does not work since the whole expression is not a string. Any idea how can I plugin dynamic classname into the above expression to get the table scheme dynamically?

Thanks.

1 Answer 1

2

I think in php 5.3+ you can do:

 $dynamic_class='\\models\\common\\'.$_GET['classname'];
 $columns=$dynamic_class::getTableSchema()->columns;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.