php - How to get a model instance in CodeIgniter hooks -
i'm tring write hook. it's easy load model , execute functions defined in it. jusk like:
$this->load->model('requestmodel'); $this->requestmodel->insert();
but in hook, there no $this
, , know works:
$ci =& get_instance(); $ci->load->model('requestmodel'); $ci->requestmodel->hook_triggered_action();
but that's hard-coded way, want is:
global $rtr; $controller = $rtr->class; $modelname = $controller.'model'; $ci->load->model($modelname); $ci->$modename->hook_triggered_action(); // line throws error
i tried $ci->model[$modename]->hook_triggered_action();
it's wrong. how?
$ci->model[$modelname]
this doesn't work in php. ->
, []
not interchangeable.
you should able however:
$ci->$modelname->hook_triggered_action();
Comments
Post a Comment