To enable hook, go to application/config/config.php/ file and set it TRUE as shown below,
$config[‘enable_hooks’] = TRUE;
To enable hooks in CodeIgniter, you need to follow these steps:
- Open the
config.php
file: Navigate to your CodeIgniter application’sconfig
directory and open theconfig.php
file. - Enable hooks: Locate the
$config['enable_hooks']
variable in theconfig.php
file and set its value toTRUE
.php$config['enable_hooks'] = TRUE;
- Configure hooks: Now, create a
hooks.php
file if it doesn’t already exist in theconfig
directory. Define your hooks in this file. Hooks are defined as an associative array where the key is the hook name and the value is an array containing the hook details like the file name, class name, and method name.php$hook['pre_controller'] = array(
'class' => 'MyClass',
'function' => 'MyFunction',
'filename' => 'MyClass.php',
'filepath' => 'hooks',
'params' => array('param1', 'param2')
);
pre_controller
: This hook is triggered immediately prior to any of your controllers being called.'class'
,'function'
,'filename'
, and'filepath'
define the class, method, filename, and file path of the hook respectively.'params'
: Optional parameter, an array that contains parameters passed to the hook method.
- Create the hook file: Create the hook file as defined in the
'filename'
and'filepath'
configuration. In this example, it would beMyClass.php
within thehooks
directory.php
class MyClass {
function MyFunction($param1, $param2) {
// Your hook logic here
}
}
Make sure your hook class and method exist and perform the desired actions.
With these steps, hooks will be enabled in your CodeIgniter application, and the specified hook(s) will be triggered based on the defined event(s).