Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load hook for particular controller

I am new in codeigniter. I want to load hooks for admin panel controller.

$hook['post_controller_constructor'][] = array(
    'class'    => 'AdminData',
    'function' => 'myfunction',
    'filename' => 'loginhelp.php',
    'filepath' => 'hooks',
    'params'   => array()
);
like image 211
Pavnish Yadav Avatar asked Apr 29 '26 08:04

Pavnish Yadav


2 Answers

Ok this is the simplest way to do this:

declare a public variable in your Controller

public $is_hookable = TRUE;

Then inside your hook function do this:

$ci=&get_instance();

if($ci->is_hookable){
  ... enter whatever you want here;
}

hope this was helpful

like image 140
jfindley Avatar answered May 01 '26 09:05

jfindley


please read the document clearly https://ellislab.com/codeigniter/user-guide/general/hooks.html

The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:

$config['enable_hooks'] = TRUE;

Hooks are defined in application/config/hooks.php file.

You cannot load it for specific controller.You need to check controller name at hooks function and write code. suppose your post_controller_constructor hooks function name is myfunction you can check it inside the function

 $CI =& get_instance();
 if($CI ->router->class=="AdminData"){//write your code}
like image 38
Shaiful Islam Avatar answered May 01 '26 07:05

Shaiful Islam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!