我正在使用基本的 MVC 进行练习,但出现此错误:
Fatal error: Call to a member function run() on a non-object in Router.php on line 5
我究竟做错了什么?
核:
<?php
class Core {
protected $router;
protected $controller;
public function run() {
$this->router =& load_class('Router');
$this->controller =& load_class('Controller');
$this->router->run();
}
}
路由器:
class Router extends Core {
public function run() {
echo $this->controller->run();
}
}
控制器:
class Controller extends Core {
public function run() {
return 'controller';
}
}
哦,还有 load_class 函数
function &load_class($class_name) {
$path = ROOT . 'system/classes/' . $class_name . '.php';
if (file_exists($path)) {
include_once($path);
if (class_exists($class_name)) {
$instance = new $class_name;
return $instance;
}
}
return false;
}
提前非常感谢。