What is hook?
CodeIgniter’s Hooks feature modify the core functionalities of the framework without changing the core files. For example, If you want to run a script right before your controllers get loaded, or right after or at any other location, you can use Hook.
How many types of hooks are there in Code Igniter?
There are 7 available hook points:
pre_system
Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.
pre_controller
Called prior to controllers being called. All base classes, routing, and security checks have been done
post_controller_constructor
Called after controller is instantiated, but prior to any method calls happening.
post_controller
Called after the controller is executed.
display_override
Overrides the _display() method, used to send the finalised page to the web browser at the end of system execution. This permits you to use your own display methodology.
Note that you will need to reference the CI super object with $this->CI->get_instance() and then the finalised data will be available by calling $this->CI->output->get_output().
cache_override:
post_system:
How to Create a Hook in CodeIgniter?
<?php $my_hook = array( 'class' => 'YourClassname', 'function' => 'your_function_name', 'filename' => 'your_filename.php', 'params' => array('p1', 'p2'), 'filepath' => 'hooks' ); $hook['pre_controller'] = $my_hook; ?>
Can we use multiple call to same hook?
What are the benefits of using hook in an application?
What is HMVC?
What is a module?
What is difference between Library and Helper?
What is Routes in Code Igniter Framework?
How to use or enable libraries CodeIgniter?
$this->load->library('my_library_class');