Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added multiple sub folder support for controllers. #982

Closed
wants to merge 4 commits into from

4 participants

@conradkleinespel

Controllers can be stored in sub folders so as to allow for better organisation of controller files if needed.

It is optional and set off by default, since not everyone needs this and it could slow down the system.

To switch it on, set $routes['allow_multiple_subfolders'] in application/config/routes.php to TRUE.

@conradkleinespel

What do you mean ? This is the first time I make a pull request. Did I do something wrong ?

@dfreerksen

He's referring to the .gitignore file.

@conradkleinespel

Messed up the first commit. Should all be fine now. Thanks for pointing this out.

@conradkleinespel conradkleinespel Made multiple subfolder support for controllers optionnal. It can be …
…turned on by setting $routes[allow_multiple_subfolders] to TRUE in the routes config file.
079eb0d
@conradkleinespel

I'm just posting a commit that I find useful. The CI team is free to merge or to refuse it. The thread you link to is from 2010. So until these modifications are available, if they are at some point available, I guess at least having the possibility of using multiple sub folders would be good :)

@narfbg
Owner

This is way too old and not that useful anyway.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 26, 2012
  1. @conradkleinespel
  2. @conradkleinespel
  3. @conradkleinespel
  4. @conradkleinespel

    Made multiple subfolder support for controllers optionnal. It can be …

    conradkleinespel authored
    …turned on by setting $routes[allow_multiple_subfolders] to TRUE in the routes config file.
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 3 deletions.
  1. +8 −1 application/config/routes.php
  2. +12 −2 system/core/Router.php
View
9 application/config/routes.php
@@ -68,5 +68,12 @@
$route['404_override'] = '';
+/**
+ * To allow controller files to be stored in multiple subfolders,
+ * such as "controllers/sub1/sub2/controller_here.php",
+ * set allow_multiple_subfolders to TRUE
+ **/
+$route['allow_multiple_subfolders'] = FALSE;
+
/* End of file routes.php */
-/* Location: ./application/config/routes.php */
+/* Location: ./application/config/routes.php */
View
14 system/core/Router.php
@@ -273,7 +273,17 @@ protected function _validate_request($segments)
// Set the directory and remove it from the segment array
$this->set_directory($segments[0]);
$segments = array_slice($segments, 1);
-
+
+ if($this->routes['allow_multiple_subfolders'] === TRUE)
+ {
+ // Check for subfolders
+ while(count($segments) > 0 && is_dir(APPPATH.'controllers/'.$this->fetch_directory().$segments[0]))
+ {
+ // Set the directory and remove it from the segment array
+ $this->set_directory($this->fetch_directory().$segments[0]);
+ $segments = array_slice($segments, 1);
+ }
+ }
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
@@ -448,7 +458,7 @@ public function fetch_method()
*/
public function set_directory($dir)
{
- $this->directory = str_replace(array('/', '.'), '', $dir).'/';
+ $this->directory = str_replace(array('.'), '', $dir).'/';
}
// --------------------------------------------------------------------
Something went wrong with that request. Please try again.