Acs Posted September 25, 2008 Share Posted September 25, 2008 Hey I am trying to create my own framework and I have done something with the MVC pattern. This is what I have in my action of one of my controllers. $this->loadmodel("teste"); This is just simply to load the model teste which is just this bit of code: class teste extends acs_activerecord { public function __construct() { parent::__construct(); } } Ok, this is really simple stuff. My problem really begins in the loadmodel function, I have placed here the relevant code: //loadmodel function if (is_file($mpath)) { require($mpath); if (class_exists($m,false)) { //To prevent 2 calls to the autoload function (to get acs_db and acs_activerecord) //I will include the files if they don't already exist if (class_exists("acs_db",false) === false) { //I check for the files before ever instantiating the class echo "Loading the files"; require($this->configData->basedir . "acs_db." . $this->configData->common_extension); require($this->configData->basedir . "acs_activerecord." . $this->configData->common_extension); } else echo "Already Loaded"; $this->m[$m] = new $m; return $this->m[$m]; } } As you can see from the comments //To prevent 2 calls to the autoload function (to get acs_db and acs_activerecord) //I will include the files if they don't already exist I am trying to prevent 2 calls to the autoload function, one to load the acs_activerecord class and another to load the acs_db class (acs_activerecord extends that one). The problem I am having is that I get the "Already Loaded" msg every time I run this. I have placed the second parameter in class_exists to false to prevent a call to autoload, but I am still somehow calling autoload. I have here an image of the cachegrind output from xdebug: I placed a little arrow where the teste_Model.php is loaded and you see an immediate call to autoload, but in the loadmodel function you can see that I just require the file, check if the class exists and then check if the acs_db class exists and try to load it. Only after this do I instantiate the class. So my question here, is how the heck do I have those calls to autoload if I am not instantiating the class?? Thanks PS: I have attached the cachegrid output in case any one wants to see it. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/125820-loading-issues/ Share on other sites More sharing options...
Acs Posted September 25, 2008 Author Share Posted September 25, 2008 Well I failed to notice before, but the files are actually being loaded when I do a require to the class file. Is this correct?? The teste_Model.php only has this code <?php class teste extends acs_activerecord { public function __construct() { parent::__construct(); } } ?> It doesn't instantiate anything. How can this call the acs_activerecord??? Quote Link to comment https://forums.phpfreaks.com/topic/125820-loading-issues/#findComment-650830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.