d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php - Loading Classes > Need Some Help!
Add Reply New Topic New Poll
Member
Posts: 57
Joined: May 23 2012
Gold: 0.00
Warn: 10%
Dec 4 2012 02:57pm
Hi guys,

Im trying to make my own (very simple) MVC framework,
Atm i have a problem with loading classes,

i have a main controller class , in which i made a loadModel function like this :

Quote
    public function loadModel ( $model ){
       
        if (!file_exists(ROOT . '/models/' . $model . '.php'))
        {
          throw new Exception('Cannot load model : '.$model.'');
        }
        else {
           
            include (ROOT . '/models/' . $model . '.php');           
            $model = new $model;     
        }       
 


In my controller for the homepage (extends the main controller) i use the function like this : $this->loadModel('queries') .

When i use a var_dump in the loadmodel function like this : var_dump($model) it says an object has been created, however i cannot use this object in my homepage controller, it simply does not exist there somehow

Any1 knows how to fix this? I could just use include and make an object of it, but i want it do be done automaticly, so i can save time with this later


thanks!
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Dec 7 2012 04:17pm
The file has to be included if you wish to call or use that public function...
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll