Welcome Guest, Not a member yet? Register   Sign In
calling controllers with hook
#1

[eluser]Unknown[/eluser]
Hi all,

Can I call a controller with a pre_controller hook.

Something like this, where ControllerHook is a normal controller.

Code:
$hook['pre_controller'][] = array(
  'class'    => 'ControllerHook',
  'function' => 'controllerHookFunction',
  'filename' => 'ControllerHook.php',
  'filepath' => 'hooks',
);

I tried this already, it works fine. On problem is that post hook processing I get this error
Code:
Fatal error: Call to a member function _assign_libraries() on a non-object in F:\xampp\htdocs\trunk\system\libraries\Loader.php on line 1038

I dont know what is the issue here.

Thanks in advance,
Shikhar
#2

[eluser]Colin Williams[/eluser]
The issue is that the Controller hasn't bee loaded (I mean, c'mon, the name of the hook is 'pre_controller').

You might want to move whatever code you have into the controller constructor.

And your next remark is, "But I don't want to paste it into every controller." To which I say, "Put in the parent class, Controller or MY_Controller"
#3

[eluser]Unknown[/eluser]
Thanks for the reply Collin,

I know I can do it easily by extending the controller but I dont want to do that.
I wanted to manage this with a hook.

Yes, even though its a pre controller hook, the controller hook works fine as expected .. the problem is when the CI processes the request further I get this error.

I tried with post_controller_constructor and post_controller the controller hook doesnt work.

regds,
Shikhar




Theme © iAndrew 2016 - Forum software by © MyBB