• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with URI routes

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:


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


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.

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.


$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.

[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:
* 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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.