【发布时间】:2018-09-15 05:01:50
【问题描述】:
我有这个主控制器:
namespace App\Core;
/**
* Controller class
*/
class Controller
{
/** @var View View The view object */
public $View;
public $templates;
/**
* Construct the (base) controller. This happens when a real controller is constructed, like in
*/
public function __construct()
{
}
public function loadModel($name) {
$path = '\\App\\Front\\Model\\'.$name; // Not Work
//$this->model = new \App\Front\Model\IndexModel(); Work
$this->model = new $path;
return $this->model;
}
}
在 IndexController 我有:
namespace App\Front\Controller;
use App\Front\Model\IndexModel;
class IndexController extends \App\Core\Controller {
public function index(){
$this->loadModel('IndexModel()')->test();
}
}
现在我看到了错误:
致命错误:未捕获的错误:在 /Applications/MAMP/htdocs/mvc/application/Core/Controller.php:64 中找不到类“\App\Front\Model\IndexModel()”
如何修复错误?
【问题讨论】:
-
@MagnusEriksson:修复!!谢谢
-
我做了一个回答。既然它对您有用,请随时接受它,以便其他人知道问题已得到解决。
标签: php namespaces