Jump to content

Recommended Posts

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:

 

loadproblemug6.jpg

 

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]

Link to comment
https://forums.phpfreaks.com/topic/125820-loading-issues/
Share on other sites

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???

Link to comment
https://forums.phpfreaks.com/topic/125820-loading-issues/#findComment-650830
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.