title: use ion auth authentication for codeigniter in another controller
body: <p>I am trying to build a web application with codeigniter. I have installed Ion Auth as my authentication model.</p>
  
  <p>The default Auth.php controller authenticates the user and sets up the session.</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Auth extends CI_Controller {
  
  
  
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;library('ion_auth');
          $this-&gt;load-&gt;library('session');
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;load-&gt;helper('url');
  
          $data['title']="Login Page";
          $this-&gt;load-&gt;view("view_site_header",$data);
  
          // Load MongoDB library instead of native db driver if required
          $this-&gt;config-&gt;item('use_mongodb', 'ion_auth') ?
          $this-&gt;load-&gt;library('mongo_db') :
  
          $this-&gt;load-&gt;database();    
  
          $this-&gt;form_validation-&gt;set_error_delimiters($this-&gt;config-&gt;item('error_start_delimiter', 'ion_auth'), $this-&gt;config-&gt;item('error_end_delimiter', 'ion_auth'));
      }
  
      //redirect if needed, otherwise display the user list
      function index()
      {
          // if not logged in - go to home page
          if (!$this-&gt;ion_auth-&gt;logged_in())
          {
              //redirect them to the login page
              redirect('auth/login', 'refresh');
          }
          // if user is an admin go to this page
          elseif ($this-&gt;ion_auth-&gt;is_admin())
          {
              // if an admin, go to admin area
  
              //set the flash data error message if there is one
              $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
              //list the users
              $this-&gt;data['users'] = $this-&gt;ion_auth-&gt;users()-&gt;result();
              foreach ($this-&gt;data['users'] as $k =&gt; $user)
              {
                  $this-&gt;data['users'][$k]-&gt;groups = $this-&gt;ion_auth-&gt;get_users_groups($user-&gt;id)-&gt;result();
              }
  
              $this-&gt;_render_page('auth/view_users', $this-&gt;data);                
          }   else
      {
          //redirect them to the default home page 
          $data['title']="IMS Home Page";
          $this-&gt;load-&gt;view("generic/view_site_header",$data);
          $this-&gt;load-&gt;view("generic/view_generic_nav");
          $this-&gt;load-&gt;view("generic/view_content_generic");
          $this-&gt;load-&gt;view("view_site_footer");
      }
  }
  </code></pre>
  
  <p>what I want to do is create a new controller for my application logic and leave the auth controller for authentication. </p>
  
  <p>How can I make use of the auth controller to ensure my user is logged in when accessing my new controller? in addition I need the ession information to be available to the new controller.</p>
  
  <p>my new controller, master_data has the following code:</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Masterdata extends CI_Controller{
  
      function index ()
      {
              $data['title']="Master Data Home Page";
              $this-&gt;load-&gt;view("master_data/view_master_data_header",$data);
              $this-&gt;load-&gt;view("master_data/view_master_data_nav");
              $this-&gt;load-&gt;view("master_data/view_content_master_data_home");
              $this-&gt;load-&gt;view("master_data/view_master_data_footer");
  
              echo $this-&gt;session-&gt;userdata('username');
  
  
  
      }
  }
  </code></pre>
  
  <p>obviously the <code>echo $this-&gt;session-&gt;userdata('username');</code> does not work as the new controller has no knowledge of the auth controller session.</p>
  
  <p>any help appreciated as always.</p>
  
  <p>Kind Regards,</p>