Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code was already on the internet but i modified it to make it work for codeigniter 2.1</p> <p>See the old source here: <a href="http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/" rel="noreferrer">http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/</a></p> <p>Make a new file MY_Router.php in the application/core directory, copy the following code in it:</p> <pre><code>&lt;?php /* * Custom router function v 0.2 * * Add functionality : read into more than one sub-folder * */ Class MY_Router extends CI_Router { Function MY_Router() { parent::__construct(); } function _validate_request($segments) { if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) { return $segments; } if (is_dir(APPPATH.'controllers/'.$segments[0])) { $this-&gt;set_directory($segments[0]); $segments = array_slice($segments, 1); /* ----------- ADDED CODE ------------ */ while(count($segments) &gt; 0 &amp;&amp; is_dir(APPPATH.'controllers/'.$this-&gt;directory.$segments[0])) { // Set the directory and remove it from the segment array //$this-&gt;set_directory($this-&gt;directory . $segments[0]); if (substr($this-&gt;directory, -1, 1) == '/') $this-&gt;directory = $this-&gt;directory . $segments[0]; else $this-&gt;directory = $this-&gt;directory . '/' . $segments[0]; $segments = array_slice($segments, 1); } if (substr($this-&gt;directory, -1, 1) != '/') $this-&gt;directory = $this-&gt;directory . '/'; /* ----------- END ------------ */ if (count($segments) &gt; 0) { if ( ! file_exists(APPPATH.'controllers/'.$this-&gt;fetch_directory().'/'.$segments[0].EXT)) { show_404($this-&gt;fetch_directory().$segments[0]); } } else { $this-&gt;set_class($this-&gt;default_controller); $this-&gt;set_method('index'); if ( ! file_exists(APPPATH.'controllers/'.$this-&gt;fetch_directory().'/' .$this-&gt;default_controller.EXT)) { $this-&gt;directory = ''; return array(); } } return $segments; } show_404($segments[0]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload