开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜