title: what is the best practice for role based login system in Codeigniter
body: <p>I am working on one role based login system. Actually, What should I do to the controller, model and the views in this role based login system to allocate different access criteria. </p>
  
  <p>I am little confused about how to set and access for the user according to the role. </p>
  
  <p>Mainly I am not sure about how to allocate different view as a role.</p>
  
  <p>ex. I apply if condition to check role and then view according to the role the menu show the different links. like main admin can only watch account tab. the user can not see the account tab. </p>
  
  <p>I also set the same if condition with the session in the controller for preventing direct access to that page. </p>
  
  <p>Here is my code which I applied to menu and controller. </p>
  
  <pre><code>&lt;?php 
          $login_role= $this-&gt;session-&gt;userdata('user_data');
          if($login_role['user_role'] === 'super_admin'){
  
              ?&gt;&lt;li&gt;&lt;a href="&lt;?php echo base_url('account/view_account'); ?&gt;"&gt;
              &lt;div&gt;Account&lt;/div&gt;&lt;/a&gt;&lt;/li&gt;&lt;?php
          }
      ?&gt;
  </code></pre>
  
  <p>and the same condition in the controller </p>
  
  <pre><code> public function index() 
  {
      $login_role= $this-&gt;session-&gt;userdata('user_data');
  
      if($login_role['user_role'] === 'super_admin')
      {
          $this-&gt;load-&gt;model('location_model');
          $city_list = $this-&gt;location_model-&gt;get_city_list();
          $state_list = $this-&gt;location_model-&gt;get_state_list();
          //log_message('info', 'City and State list will sucessfully loded.');         
          $this-&gt;load-&gt;view('admin/account_insert',['city_list'=&gt;$city_list,'state_list'=&gt;$state_list]);    
      } else {
  
          redirect('admin/dashboard','refresh');
      }
  
  
  }
  </code></pre>
  
  <p>I am not sure about is this safe to use like this way. or I have to do something else as a good practice.</p>