title: Codeigniter: Controlling log in privileges with inheritance
body: <p>I'm looking to do log ins with my codeigniter project.</p>
  
  <p>Some considerations:</p>
  
  <p>1) There are two controllers that are outside that do not require authentication. One for information (splash_pages and such), and the other to create a logged in session.</p>
  
  <p>2) All other controllers inherit from a master Controller that as part of its constructor, requires you to be logged in or it kicks you to the log in screen.</p>
  
  <p>So far the above 2 works fine for logged in vs logged out.</p>
  
  <p>In terms of code:</p>
  
  <p>The master controller I was describing for 2)
  This is located in the Core folder of Codeigniter</p>
  
  <pre><code>class MY_Controller extends CI_Controller
  {
      public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;library('cart');
          $this-&gt;load-&gt;library('session');
          $this-&gt;load-&gt;helper('form');
          $this-&gt;load-&gt;library('form_validation');
          if (!$this-&gt;session-&gt;userdata('loggedin')){
              redirect('/sessions/log_in/','refresh');
          }
      }
  </code></pre>
  
  <p>A class using the login system:</p>
  
  <pre><code>class Records extends MY_Controller {
  
      public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;model('some_model');
          $this-&gt;load-&gt;library('some_library');
      }
  </code></pre>
  
  <p>The idea is that on object construction, it will check whether the user is logged in or not and either construct the object correctly or redirect to the log in screen.</p>
  
  <p>However, the needs of the project have changed a bit. The requirements now state that there are around 6 different user groups arranged whose privileges can be arranged into subsets. A can do I, B can do A + II, C can do B + III, and so on. There has been slight hints that there may be privileges that are not strictly subset (IE only B can do task IV), but this has not been confirmed yet so I want to keep my options open.</p>
  
  <p>How I am envisioning doing it is having a bunch of Controllers from MY_Controller that inherit from MY_Controller.</p>
  
  <p>For example in the Core folder:</p>
  
  <pre><code>class MY_AsController extends MY_Controller {
      public function __construct(){
          parent::__construct();
          $accountType = $this-&gt;session-&gt;userdata('accountType');
          if(!($accountType == declaredConstant)){
              redirect('/someController/someMethod','refresh');
          }
      }
  </code></pre>
  
  <p>Then in the controllers folder:</p>
  
  <pre><code>class AControlPage extends MY_AsController {
       //Insert page functions that only As have access to here
  }
  </code></pre>
  
  <p>Unfortunately, applying it in practice doesn't generate any errors, only a blank page.
  I'm not sure what to after that though.</p>