title: Codeigniter Redirect/Load view
body: <p>I really want to understand whats the best use of both functions.</p>
  
  <p>Controller: (After much processing, lets skip directly to creating the session)</p>
  
  <pre><code>$isLoggedin = array( 'user_name' =&gt; $row['username'] , 'user_type' =&gt; 'user' ,  'is_loggedin' =&gt; TRUE);
  $this-&gt;session-&gt;set_user($isLoggedin); 
  redirect('controller/index');
  </code></pre>
  
  <p>in the controller,</p>
  
  <pre><code>public function __construct()
  {
  parent::__construct();
      //should i check for the session here?
  }
  
  function index(){
   // or should i check here?
  }
  </code></pre>
  
  <p>In the login controller, after creating the  session, i passed it to the main controller, Before accessing the homepage, i want to verify if the <code>session['is_loggedin'] == TRUE</code> that signifies the session that was created = logged in. </p>
  
  <p>My confusion is, since the constructor function is loaded first right everytime you call the controller. Please correct me if im wrong.  So in the redirect in the log in controller, i shouldnt call the index? </p>
  
  <p>should i just call the controller there then let the constructor handle, then in the constructor, like this.</p>
  
  <pre><code>public function __construct(){
  parent::__construct();
  if($session['is_loggedin'] == TRUE)
  $this-&gt;load-&gt;view('homepage');
  else
  redirect('Login');
  }
  </code></pre>
  
  <p>So i guess i wont need the index anymore right? Is it okay to call the controller that way? in the redirect, also do i have to pass the $session from controller to controller?</p>