Concatenation while instantiating a class
I'd like to instantiate a model (in Zend Framework) using a generic way. I have $type
variable which contains the name of the model. I'd like to write something like this
$db = new Admin_Model_{$type}();
But it doesn't work, Is there any way to 开发者_C百科accomplish this?
You need to have the entire class name as a string in order for this to work:
$model = 'Admin_Model_' . $type;
$db = new $model();
精彩评论