Hooks in Codeigniter

0
Hooks in Codeigniter:-
 
Hooks are used to providing an implicit event method that will be called during the application flow cycle.

for example, if we want to call functionality under before System load, System unloads, Before Constructor, after constructor then we can use hooks.


Codeigniter Provide Multiple hooks point to define the application functionality.


CI provides multiple hooks point to write functionality.

The following is a list of available hook points.
  • pre_system:-  call before application load
  • pre_controller:-  call before controller load
  • post_controller_constructor:-  call with constructor initialization
  • post_controller Called immediately after your controller is fully executed.
  • display_override Overrides the _display() method,
  • cache_override Enables you to call your own method instead of the _display_cache() method in the Output Library.
  • post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.
Step to create Hooks:-

1)enable hooks in config.php

$Enable_hooks=True

2)  Create hooks filer under application/hooks folder

3 ) define hooks point under config/hooks.php, define filename, class name and method name
       or filename, method name





Code for hooks

application/hook.php

create info.php
<?php
function myinfo()
{
echo "<script>alert('provide 25% discount to girls only')</script>";
}

?>

call hooks in config/hooks.php


$hook['pre_system'] = array(
     
        'function' => 'myinfo',
        'filename' => 'info.php',
        'filepath' => 'hooks'
       );



Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)