CodeIgniter Forums
Help with URI routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help with URI routes (/showthread.php?tid=7474)



Help with URI routes - El Forum - 04-10-2008

[eluser]Temple[/eluser]
Hey All, been using CodeIgniter for a while now. A lot of my controllers are getting big, and I read you can use a folder within the application/controllers folder to break the functions down to single pages instead of a big one.

This is fantastic however, is there a way to keep routing the same even though it is a folder? What I mean is, default behavior is:

Code:
http://www.url.com/class/function/id/

However, if my controller is a folder, it becomes:

Code:
http://www.url.com/folder/class/function/id/

Is there a way to keep the URI routing as the default non folder behavior? Because of the class, it seems hard to me Sad

Thanks in advance for all replies.


Help with URI routes - El Forum - 04-10-2008

[eluser]MABUS[/eluser]
Yes, there is a way. One way is to play with the routes. You can use routes to accept any url, and point it to any of controller or controller function of your choice.

example.

$routes['class/function/:num'] = "folder/class/function/"
--------------------- ----------------------
url to accept where to be pointed


whatever matches the url to accept will be redirected to the result. It wont change the url , just redirection.


Help with URI routes - El Forum - 04-10-2008

[eluser]louis w[/eluser]
This is automatically built in. The Router will do a check to see if there is a folder with the name of segment 1 and a file with the name of the second segment.

In your example you would have this directory structure:
Code:
* application
  * controllers
    * folder
      * Function.php

The only caveat is your naming. This is not a function, its a class. Every controller has to be a class which contains methods (functions).

Check out line 189 of Router.php in the system/libraries folder. This will show you how CI loads cotrollers. If you want to change how this happens you can copy this file into your application/libaries folder and rename to MY_Router.php

Hope this info helps.