Welcome Guest, Not a member yet? Register   Sign In
Disable pre_controller hook on some controllers
#1

[eluser]taiar[/eluser]
Is there any way to disable a pre_controller hook in an arbitrary controller?

Thank's!
#2

[eluser]CroNiX[/eluser]
in your precontroller hook, you can probably check to see if the request contains whatever controller you are trying to avoid is, and just "return" so it doesn't do any further processing. Not sure, haven't needed hooks.
#3

[eluser]taiar[/eluser]
Nice, I found a sollution:

On my hook class:

Code:
class MyHookClass {

  private $exec;
  private $dontExec = array('controller1', 'controller2', ...);

  public function __construct() {
    $ci = get_instance();
    $controller_name = get_class($ci);
    if($controller_name is in $this->dontExec)
      $this->exec = false;
  }

  public function myHook() {
    if($this->exec) {
      //POW!!!!!!!
    }
  }
}

Thanks..
#4

[eluser]CroNiX[/eluser]
That's basically what I said, except instead of just returning you set a variable to false. Why not just return so it doesn't process further?
#5

[eluser]taiar[/eluser]
Because the hook can call any method of the class!

So it would execute it even I return the controller.
#6

[eluser]taiar[/eluser]
[quote author="taiar" date="1335296390"]Because the hook can call any method of the class!

So it would execute it even I return the controller.[/quote]

http://ellislab.com/codeigniter/user-gui...hooks.html




Theme © iAndrew 2016 - Forum software by © MyBB