1.

What is hooks in codeIgnitor and explain some of them with example.

Answer»

Hooks provides a way in codeIgnitor to modify the INNER working of a framework WITHOUT hacking the core files of the framework. Codeingitor follows a specific process to execute REQUEST (explained in QA3) but there may be some instances when a developer wants to trick it. Hooks plays a vital role to deal with such situations. 

The hooks feature can be globally enabled/disabled by setting the 

$config['enable_hooks'] = TRUE; In the application/config/config.php file:

Hooks can be defined in the application/config/hooks.php file. Each hook is specified as an array in the following format. 

$hook['pre_controller'] = array(         'class'    => 'MyClass',         'function' => 'Myfunction',         'filename' => 'Myclass.php',         'filepath' => 'hooks',         'params'   => array(param1, ‘PARAM2’, 'param3') );

Different types of hook POINTS in codeIgnitor are: 

  • Post_controller_constructor
  • Pre_controller
  • post_controller
  • Pre_system
  • Post_system
  • Display_override
  • cache_override


Discussion

No Comment Found