php - apply codes to all controller in codeigniter -


i have simple code place in controller's constructor

$this->output->set_header("cache-control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0"); $this->output->set_header("pragma: no-cache"); 

i use code safety of logout. question is, there way put/declare code global each of controllers? because hard hard code on each controller's constructor.

thank help.

i answers best approach use hooks. first add hooks.php

 $hook['display_override'] = array(     'class'    => 'routeprocess',     'function' => 'afterroute',     'filename' => 'routeprocess.php',     'filepath' => 'hooks',     'params'   => array()  ); 

then go hooks/ folder , create routesprocess.php create file below:

class routeprocess{ function afterroute(){     $this->ci =&get_instance();      $this->ci->output->set_header("cache-control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");     $this->ci->output->set_header("pragma: no-cache");     echo $this->ci->output->get_output(); } } 

the thing not require __construct() of controller called can overridden. called no matter what.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -