2

I searched for calling/invoking a hook manually and similar stuff on the web but couldn't find anything. Is there a such thing in codeigniter? I have a hook below which gets triggered as expected but just in case if doesn't, then I want to invoke it manually in my code.

Thanks

$hook['post_controller_constructor'] [] =
array(
    'class'    => 'load_designs',
    'function' => 'do_load',
    'filename' => 'load_designs_hook.php',
    'filepath' => 'hooks',
    'params'   => ''
    );
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
BentCoder
  • 12,257
  • 22
  • 93
  • 165

1 Answers1

4

In order to call a hook, you could load the Hooks core class and call the hook by _call_hook() method as follows:

In your Controller:

$hook =& load_class('Hooks', 'core');
$hook->_call_hook('post_controller_constructor');

However, if you need to call a specific method of a hook class, you should do that manually:

if (! file_exists($file_path = APPPATH . 'hooks/MyClass.php'))
{
    exit('The hook file does not exist.');
}

// load the hook file.
require $file_path;

$hook = new MyClass();
$hook->Myfunction(array('Hello', 'World!'));

You can also make a helper function to do the above logic if needed.

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164