Before I start just letting you know that I’m new to OOP programming so take it easy on me.
I’m currently working on a PHP framework and I’ve been able to route my traffic through one entry point. This is the structure below..
index ----> bootstrap ----> router ----> controller
Here’s the main 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();
}
}
In my construct function it’s suppose to set the…
$this->$model = new $model; and $this->_view = new view;
But when I run either $this->_view->render(); or $gamerequests_array = $this->main_model->tab_query($tab);
It says the object doesn’t exist. Here’s the exact error message I get.
Notice: Undefined property: main_controller::$main_model and
Fatal error: Call to a member function tab_query() on a non-object
So at this point I know that the problem is the framework setting up the new objects. I’ve been trying to figure this out and at this point I need some help.
If anyone needs extra code feel free to request it, I’ll post it.
From this line:
It appears your passing in a string and using it both as the property name and the class name. Perhaps you’re passing in a name that is not exactly
main_model. Though variable/property names are case-sensitive, class names are not. So, they’re may be a case mismatch. Pass$thisthroughget_object_varsto see what properties are available. Keep in mind that dynamically adding properties in this way will make them public.These lines should be examined as well:
You’re overwriting the property. I’m sure this is unintentional and may be part of the problem you’re experiencing. Perhaps you’re trying to use the same approach as you did with the controller (store name, use for instantiation and access).