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

[eluser]nagata[/eluser]
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)) {
        //logged in, do nothing, let the index load safely...
        } else {
           redirect("admin/login");
        }
    }

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

    public function login()
    {
       $this->load->view('admin/login');
    }
}
Its just Index is an initial page loaded if there is no function defined when u are going somewhere
ex: u have admin panel controller,
if u visit admin it will load by default the index()
if there was a function given it will then admin/(function)
...
u see...
it should do anything when user is logged in, if he isnt then just redirect him to login page...


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