title: CodeIgniter autoload specific classes
body: <p>I have created two controllers, the Public_Controller and the Admin_Controller inside <em>./application/libraries</em> folder, following Phil's Sturgeon <a href="http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY" rel="noreferrer">example</a>. </p>
  
  <p>What I want to do is to autoload the Public_Controller and Admin_Controller specificly, so I created this autoload function inside ./application/config.php</p>
  
  <pre><code>function __autoload($class) {
  
      // Autoload only Public_Controller and Admin_Controller
      if (strpos($class, 'CI_') !== 0) {
          $file = APPPATH . 'libraries/'. $class .'.php';
          if ( file_exists($file) &amp;&amp; is_file($file) ) {
              @include_once($file);
          }
      }
  }
  </code></pre>
  
  <p>The problem with this I think is that I have more files included inside the libraries folder, so those too are autoloaded, which is not what I want. So instead I tried to do a small change to the first if statement, like this:</p>
  
  <pre><code>if ( in_array($class, array('Public_Controller, Admin_Controller')) ) // instead of strpos
  </code></pre>
  
  <p>in order to target only these two classes, but this does not seem to work. Any ideas what I might doing wrong?</p>