Welcome Guest, Not a member yet? Register   Sign In
Check a function before doing anything?
#4

I used a 'post_controller_constructor' hook to do this:

Hook in config/hooks.php:
PHP Code:
$hook['post_controller_constructor'] = array(
 
   'class'     => 'Auth',
 
   'function'  => 'check',
 
   'filename'  => 'Auth.php',
 
   'filepath'  => 'hooks',
); 

Check Function in hooks/Auth.php:
PHP Code:
   public function check()
 
   {
 
       // get the current controller and method from the url
 
       $controller     $this->CI->uri->segment(1,'none');
 
       $method         $this->CI->uri->segment(2,'none');

 
       // if the user is not logged in && the request is not requests or login
 
       if ((!$this->CI->User->isLoggedIn) && ($controller != 'requests') && ($method != 'login') ) {
 
           redirect('/requests/login');
 
       }
 
   

See the docs for reference. Good luck.
Reply


Messages In This Thread
RE: Check a function before doing anything? - by chrismartinez99 - 04-22-2015, 08:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB