在我开始让您知道我是 OOP 编程的新手之前,请放轻松。
我目前正在开发一个 PHP 框架,并且我已经能够通过一个入口点路由我的流量。这是下面的结构..
index ----> bootstrap ----> router ----> controller
这是主控制器...
class controller {
protected $_model;
protected $_controller;
protected $_id;
protected $_view;
function __construct($controller,$model,$view,$id=NULL) {
$this->_controller = $controller;
$this->_id = $id;
$this->_model = $model;
$this->_view = $view;
$this->$model = new $model;
$this->_view = new view;
}
function filter($data) {
$data = trim(htmlentities(strip_tags($data)));
if (get_magic_quotes_gpc())
$data = stripslashes($data);
$data = mysql_real_escape_string($data);
return $data;
}
function set($name,$value) {
$this->_view->set($name,$value);
}
function __destruct(){
$this->_view->render();
}
}
在我的构造函数中,它应该设置...
$this->$model = new $model;
和$this->_view = new view;
但是当我运行$this->_view->render();
或者$gamerequests_array = $this->main_model->tab_query($tab);
它说该对象不存在。这是我得到的确切错误消息。
Notice: Undefined property: main_controller::$main_model
和
Fatal error: Call to a member function tab_query() on a non-object
所以在这一点上,我知道问题在于设置新对象的框架。我一直在努力解决这个问题,此时我需要一些帮助。
如果有人需要额外的代码,请随时请求,我会发布它。