问题:
// TODO: add $name to $models array in Controller class
如何$name
从类中的函数添加model()
到Load
类中的$models
数组Controller
?
注意:我在单独的文件中有Load
和类。Controller
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;
}
}
编辑:
我的目标:如果我在 Controller 中加载模型是这样的:$this->load->model('model_name');
那么我希望将该加载模型的实例作为$this->model_name->method();