• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can the hook be used in the controllers which I want?

#1
Hi,friend!
For example, there are several controllers.(controller A, controller B)
I want to use the hook "post_controller_constructor" in controller A, but not in controller B.
How to do?
Thinks.
Reply

#2
Hi qzzm.

You can do this in hook:

//Get codeiginiter instance
$CI =& get_instance();

//get controller
$controller = $CI->router->fetch_class();

//get method (OPTIONAL)
$method = $CI->router->fetch_method();

if($controller == 'controllerA'){
//DO ACTION!
}
Reply

#3
This isn't a Hooks job. If you want some code to run only for a certain controller, then put it inside that controller.
Reply

#4
(04-09-2015, 12:23 AM)davidgv88 Wrote: Hi qzzm.

You can do this in hook:

//Get codeiginiter instance
$CI =& get_instance();

//get controller
$controller = $CI->router->fetch_class();

//get method (OPTIONAL)
$method = $CI->router->fetch_method();

if($controller == 'controllerA'){
    //DO ACTION!
}
Thinks, davidgv88.
It's a good idea. Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.