I can't figure out how to call an insertValue function for the following setup:
This is my bootstrap. It sets my controller and loads its model. (not really important)
<?php
$controller = new Register;
$controller->loadModel('register');
?>
This is the controller class which has the loadModel function.
class Controller {
public static $model;
public function loadModel($name) {
$path = 'models/'.$name.'Model.php';
if(file_exists($path))
{
require 'models/'.$name.'Model.php';
$modelName = $name .'Model';
$this->model = new $modelName;
}
}
}
This is the parent model class:
class Model {
public static $database;
function __construct() {
$this->database = new Database();
}
}
Now the Database class has a function called insertValue() that I want to call, and the register class is where I want to call it from. It's an extension of Controller
The register class appears as follows:
class Register extends Controller {
function __construct() {
parent::__construct();
$this->view->render("register", "index", "Register", TRUE);
}
...
I tried calling it like so:
$this->model->database->insertValue();
but it doesn't even execute.
I think it's because your fields database and model is static. But you are call it dynamicly. Try to remove the static declaration.