Welcome Guest, Not a member yet? Register   Sign In
Class not found
#6

[eluser]phpoet[/eluser]
I often put simple authentication checks in the constructor of my Controller. For example, if I were coding a blog, I might do something like this.

Code:
class Blog extends Controller {

  /**
   * Check authentication before executing any actions
   */
  public function __construct() {
    parent::__construct();
    $this->_check_authentication();
  }

  /**
   * Only allow unauthenticated access to a
   * the sign_in and register actions
   */
  private function _check_authentication() {
    $exceptions = array("sign_in", "register");
    $action = $this->uri->segment(2);
    if(!in_array($action, $exceptions)) {
      if(!$this->session->userdata('logged_in')) {
        $this->session->sess_destroy();
        redirect('blog/sign_in');
      }
    }
  }

}


Messages In This Thread
Class not found - by El Forum - 09-02-2008, 04:25 PM
Class not found - by El Forum - 09-03-2008, 03:15 AM
Class not found - by El Forum - 09-03-2008, 03:57 AM
Class not found - by El Forum - 09-03-2008, 09:55 AM
Class not found - by El Forum - 09-03-2008, 11:16 AM
Class not found - by El Forum - 09-03-2008, 12:45 PM
Class not found - by El Forum - 09-03-2008, 01:19 PM
Class not found - by El Forum - 09-03-2008, 03:33 PM
Class not found - by El Forum - 09-03-2008, 04:17 PM
Class not found - by El Forum - 09-03-2008, 05:04 PM
Class not found - by El Forum - 09-03-2008, 07:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB