codeigniter Defining a Hook


Hooks are defined in application/config/hooks.php file. Each hook is specified as an array with this prototype:

$hook['pre_controller'] = array(
      'class'    => 'MyClass',
      'function' => 'Myfunction',
      'filename' => 'Myclass.php',
      'filepath' => 'hooks',
      'params'   => array('bread', 'wine', 'butter')
  • CLASS- The class that you wish to invoke if it is procedural code leave it as blank.
  • FUNCTION- The function name you wish to call.
  • FILENAME- The file name containing your class/function.
  • FILEPATH- Location of the hook file.
  • PARAMS-Additional parameter if needed it is optional