質問:
// 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;
}
}
編集:
私の目標:コントローラーにモデルを次のようにロードする場合:$this->load->model('model_name');
そのロードされたモデルのインスタンスを次のように持ちたい$this->model_name->method();