1.

What are the available hooks in codeIgnitor.

Answer»

Hooks are the events which can be called before or after the execution of a program. Hooks stored in a specific DIRECTORY allows the codeIgnitor execution PROCESS without MODIFYING core FILES

There are two hook files in CodeIgniter. One is application/config/hooks.php folder and other is application /hooks folder.

  • If a code is to be run every time with controller execution then you can write that in hooks. 
  • To enable Hook, go to application/config/config.php file and set it TRUE as shown below.
$config['enable_hooks'] = TRUE; 

To define a hook :

$hook['post_controller'] = array(               'class' => 'Classname',               'function' => 'functionname',               'filename' => 'filename.php',               'filepath' => 'hooks',               'params' => array('element1', 'element2', 'element3')               );  
  • Class: Name of your class defined in hooks.php file. 
  • Filepath: Here you have to mention the name of the directory which contains your script. Your script must be located inside the application folder. If your script is located in application/hooks folder, then your path will be simply hooked. But if your script is located in application/hooks/customfolder, then your path will be hooks/custom.

List of available hooks are : 

  • Pre_system
  • Pre_controller
  • Post_controller_constructor 
  • Post_controller
  • Display_override
  • Cache_override
  • Post_system


Discussion

No Comment Found