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

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -