title: Change default controller directory of Codeigniter
body: <p>I want to have two folders where save codeigniter's controllers:</p>
  
  <pre><code>/application/controllers
  /application/buckets
  </code></pre>
  
  <p>i'm a order paranoic person and i want to separate two types of my controllers.</p>
  
  <p>In bucket folders the structure app was this:</p>
  
  <pre><code>/application/buckets/example/index.php
  /application/buckets/example2/index.php
  /application/buckets/example3/index.php
  </code></pre>
  
  <p>¿Maybe extending the router class?</p>
  
  <p>A working example:</p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  /*
      Extended the core Router class to allow for sub-sub-folders in the controllers directory.
  */
  class App_Router extends CI_Router {
  
      function __construct()
      {
          parent::__construct();
      }
  
      function _validate_request($segments)
      {
          if (count($segments) == 0)
          {
              return $segments;
          }
  
          if (file_exists(APPPATH.'buckets/'.$segments[0].'/index.php'))
          {
  
  
              $this-&gt;set_directory(APPPATH.'buckets/'.$segments[0]);
              $this-&gt;set_class(ucfirst($segments[0]));
              $this-&gt;set_method(isset($segments[1]) ? $segments[1] : 'index');
  
              return $segments;
          }
      }
  }
  </code></pre>