title: Codeigniter: HELPERS and $CI =& get_instance();
body: <p>I have a few functions that manage the access levels of a certain controllers within the controller file.</p>
  
  <p>I decided to take them out either to a library or to a helper.</p>
  
  <p>Since they are mostly procedural I decided to use helpers.</p>
  
  <p>Here is the original method in the controller file (others are access_level_member, access_level_moderator etc)</p>
  
  <pre><code>  function access_level_admin() {
  
      if (!$this-&gt;session-&gt;userdata('loggedin')) {
          $this-&gt;session-&gt;set_flashdata('warning', 'Not logged in.');
          redirect('/start_page', 'refresh');
      }
      if (!$this-&gt;session-&gt;userdata('admin')) {
          $this-&gt;session-&gt;set_flashdata('warning', 'Access Denied!');
          redirect('/start_page', 'refresh');
      }  
  </code></pre>
  
  <p>Here is it withing a helper.</p>
  
  <pre><code>function access_level_admin() {
      $CI =&amp; get_instance();
      if (!$CI-&gt;session-&gt;userdata('loggedin')) {
          $CI-&gt;session-&gt;set_flashdata('warning', 'Not logged in.');
          redirect('/start_page', 'refresh');
      }
      if (!$CI-&gt;session-&gt;userdata('admin')) {
          $CI-&gt;session-&gt;set_flashdata('warning', 'Access Denied!');
          redirect('/start_page', 'refresh');
      }  
  </code></pre>
  
  <p>So my question is, is it a better idea to place it in a library or a helper and is it ok to use $CI =&amp; get_instance(); within a helper.</p>
  
  <p>Any better ideas or recommendations?</p>