Saturday, October 24, 2015

Skip to execute construct method when certain method called

Sometime we don't need to execute any method / code inside constructor/destructor.
example for codeigniter

class Student
{
public function __construct ()
{

        // we want to skip 2 methods(login and logout) in this 'student' class.
$exception_uris = array(
'student/login', 
'student/logout'
);

//  check called class and method from URL.If  called method are not those login/logout execute code
 
if (in_array(uri_string(), $exception_uris) == FALSE)
   {
 
       if ($this->student_m->loggedin() == FALSE)
      {
redirect('student/login');
}
}    
}
}

Total Pageviews