douyan4900 2014-04-12 19:50
浏览 58
已采纳

PHP使用变量声明类

Im trying to execute the following code

$our_controller = new App\Controllers\$routing->_new['controller']();

But Im getting 'Unexpected $routing'

And this is the class Im trying to load looks like

namespace App\Controllers;

class HomeController extends BaseController
{
      public function __construct()
      {
          parent::__construct();
      }
}

If I type the following

$our_controller = new App\Controllers\HomeController();

Works perfectly but I must use the variable instead of HomeController

  • 写回答

1条回答 默认 最新

  • dongyihao9887 2014-04-12 19:56
    关注

    Try this, I think it should work:

    $namespace = 'App\Controllers\' . $routing->_new['controller']();
    
    $our_controller = new $namespace;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?