title: Avoid repeating session and access right checks in codeigniter 3 controller
body: <p>I have implemented a simple role check code with the help of helpers using sessions in my codeigniter 3 application.</p>
  
  <p>Access Helper: Defines a function named as access_right which checks if the logged in user has access right to visit a specific module or not and correspondingly returns true or false.</p>
  
  <p>In addition to it, I also have two versions of navigation bars one for admin user and for non admin users.</p>
  
  <p>In controller i have added following code to perform the check for both i.e. which navigation to load and if the logged in user has access or not to module:</p>
  
  <pre><code>if($this-&gt;session-&gt;userdata('user-type') === 'admin')
      {
          $this-&gt;load-&gt;view('templates/sub_header_admin');
      }
      else 
      {
          $this-&gt;load-&gt;view('templates/sub_header');
      }
  
      if(access_right('client_information'))
      {
          $this-&gt;load-&gt;view('pages/clientview/client_page');
      }
      else 
      {
          $this-&gt;load-&gt;view('templates/restricted_access');
      }
      $this-&gt;load-&gt;view('templates/footer');
  </code></pre>
  
  <p>Problem is I need to repeat this much of code in each and every method inside a controller.</p>
  
  <p><code>access_right('client_information')</code>, of-course instead of client_information i check for different value like 'operator_information' depending on which controller is loaded.</p>
  
  <p>How can i avoid this repetition of code ?</p>