-3

I can't seem to figure out a way to call a method called insertValue();

My bootstrap takes the url and splits it into pieces so www.URL.com/register/register becomes

url[0]=register;  
url[1] = register;  
$controller = new url[0];  
$controller->loadModel();  
if islet($url[1])  
    $controller->{url[1]};  

class Controller { 
    public $model; 
    function __construct() { 
        $this->view = new View(); //(irrelevant) 
    } 
    public function loadModel($name) { 
        ... 
        $this->model = new $modelName; 
    }
}

The model class is as follows

class Model { 
    public $database;
    function__construct() { 
        $this->database = new Database();
    } 
} 

So the database class is as follows

class Database { 
    insertValue(){ 
    ... 
    }
}

Now, I have a bootstrap which creates a register class that extends controller as follows:

class Register extends Controller {
    function__construct(){
        parent::__construct();
    }
    public static function register (){
        HERE IS WHERE I WANT TO CALL THE INSERT VALUE FUNCTION FROM DATABASE CLASS
    }
}

The bootstrap also creates my model class by saying Register->loadModel(); which simply looks like this:

class registerModel extends Model {

    function __construct() {
        parent::__construct();
   }

I can't at all figure out how to call the insertValue function. I tried $this->model->database->insertValue(); but that didn't work.

P.S. I notice that when I call this function, that the code beneath it does not get called, but no error message is given.

tereško
  • 58,060
  • 25
  • 98
  • 150
AlexHeuman
  • 1,006
  • 1
  • 10
  • 14

1 Answers1

0

have you tried $this->model->database->insertValue() ? after calling loadModel() inside your controller construct.

gmaliar
  • 5,294
  • 1
  • 28
  • 36
  • Yes, that's what i've been trying and it doesn't seam to work. – AlexHeuman Mar 02 '13 at 20:06
  • The model automatically get's loaded in my bootstrap. $controller = new $url[0]; $controller->loadModel($url[0]); if (isset($url[2])) { $controller->{$url[1]}($url[2]); } else { @$controller->{$url[1]}(); } – AlexHeuman Mar 02 '13 at 20:07