Question:
// TODO: add $name to $models array in Controller class
How to add $name
from function model()
in Load
class to $models
array in Controller
class ?
Note: I have Load
and Controller
classes in separated files.
PHP:
<?php
class Controller {
public $models = array();
public $load;
//TODO: for each model create instance
// public $name;
public function __construct() {
$this->load = new Load();
// TODO: for each model create instance
// $this->name = new Name();
}
}
class Load {
public function model($name) {
require(APP_DIR . 'models/' . strtolower($name) . '.php');
$model = new $name;
// TODO: add $name to $models array in Controller class
return $model;
}
}
Edit:
My Goal:
If I load model in Controller as this: $this->load->model('model_name');
then I want to have instance of that loaded model as $this->model_name->method();