ハードコードされたメソッド名ではなく、変数名でロードされたモデルのメソッドを呼び出そうとしています。これにより、大量のif-thenステートメントを使用せずに、コントローラーで大量の抽象化が可能になります。
これがモデルです
class Reports_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function backlog()
{
//Do stuff
}
私が欲しいのは、変数名でバックログ関数を呼び出せるようにすることです。コントローラは次のとおりです。
class Reports extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function get_reports($report_name)
{
$this->load->model('reports_model');
$report_name = 'backlog';
$data['data'] = $this->reports_model->$report_name();
}
私が言えることから(そしておそらく私は愚かな何かを見逃している)、私のコードはhttp://php.net/manual/en/functions.variable-functions.phpの例2とまったく同じですが、私は得ています関数呼び出しの行でのこのエラー:
未定義のプロパティ:Reports :: $ reports_model