1
设置Parent属性我有鉴于这样的类:无法从子类
class View {
public function __construct() {
}
public static function render($name) {
require 'views/user/header.php';
require 'views/user/'.$name.'.php';
require 'views/user/footer.php';
}
}
,我调用视图类控制器是这样的:
class Controller {
function __construct() {
$this->view = new View();
}
}
,然后我从设置视图属性控制器子类,像这样:
class Index extends Controller {
function __construct() {
parent::__construct();
$this->view->js = "test";
}
public function index() {
$this->view->render('index/index');
}
}
但是,当我想从被设置在渲染福“的header.php”获得$这个 - > JS我总是得到这个错误信息:
Fatal error: Uncaught Error: Using $this when not in object context
我被试图检查,我在正确的类吗?使用这种方法“的header.php”文件:
echo get_class(); // and this method return "View";
,这意味着我在视图类的吧?
任何人都可以帮我吗?
在此先感谢
哦......男人。我不知道,如果我的渲染功能是静态的。现在是工作。非常感谢你@tereško。 – bagongpct