Welcome Guest, Not a member yet? Register   Sign In
Constructor in controller is behaving strangely
#1

[eluser]brianatlarge[/eluser]
In my controller, I'm checking if a session variable is set. If it is, then I know the user is logged in and I can display the site. If not, then I'll display the login page.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $user_email = $this->session->userdata('user_email');
        if(!empty($user_email)) {
            $this->index();
        } else {
            $this->login();
        }
    }

    public function index()
    {
        $this->load->view('admin/home');
    }

    public function login()
    {
       $this->load->view('admin/login');
    }
}

The problem with this is it's loading both the home and the login views. What's the deal?


Messages In This Thread
Constructor in controller is behaving strangely - by El Forum - 07-05-2012, 10:38 AM
Constructor in controller is behaving strangely - by El Forum - 07-05-2012, 11:39 AM
Constructor in controller is behaving strangely - by El Forum - 07-05-2012, 11:43 AM
Constructor in controller is behaving strangely - by El Forum - 07-05-2012, 12:07 PM
Constructor in controller is behaving strangely - by El Forum - 07-05-2012, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB