I am using hooks in my CI application “pre_controller hook specifically”.
But the problem is Hooks are activated each time a request is issued to any other controller even controllers that i don’t want the hook to be activated in.
Can hooks be enabled for only one controller? just like the @Before annotations in playframework.
Thanks in advance.
I am using hooks in my CI application pre_controller hook specifically. But the problem
Share
Why don’t you put that logic in the Constructor of your controller?
If you have multiple controllers you wish to share this functionality, simply extend the
CI_Controllerwith a new class inapplication/core/MY_Controller.phpand put the functionality in there, then in the controllers have them extend that class instead of the default CI_Controller (you can add more than one class inMY_Controller.php)!Anything that you put in the override class in
MY_Controller.phpwould execute before the code in the rest of the controller, simulating thepre_controllerhook.Just remember to call the parent constructor as well:
See the manual for more info about extending the core: https://www.codeigniter.com/user_guide/general/core_classes.html