• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tricky custom routing rules.

I am trying to implement some routing rules that are very different from the pattern used in CI. I upgrading a large web application to use CI. This application is divided into a series of sub projects and I need to specify the project for almost every request.

The users of the application are each given access to a certain set of projects within the site, and content that is for the entire site is accessible from all projects.

As a result the most logical URL pattern would be something like this:

https://mysite.com/admin -> Site wide admin
https://mysite.com/calendar -> Site wide calendar
https://mysite.com/calendar/admin -> Site wide calendar admin

https://mysite.com/PROJECTA/admin -> Project A project admin
https://mysite.com/PROJECTA/calendar -> Project A calendar
https://mysite.com/PROJECTA/calendar/admin -> Project A calendar admin

https://mysite.com/PROJECTB -> Project B home
https://mysite.com/PROJECTC -> Project C home
https://mysite.com/PROJECTD -> Project D home
https://mysite.com/ -> Site home

To make this works I figure that CI needs to translate these URIs as follows

mysite.com/admin -TO- mysite.com/admin/index/MYSITE
mysite.com/ -TO- mysite.com/welcome/index/MYSITE
mysite.com/calendar/admin -TO- mysite.com/calendar/admin/MYSITE

mysite.com/PROJECTA/admin -TO- mysite.com/admin/index/PROJECTA
mysite.com/PROJECTA/ -TO- mysite.com/welcome/index/PROJECTA
mysite.com/PROJECTA/calendar/admin -TO- mysite.com/calendar/admin/PROJECTA

Basically in all cases a project name is specified as the first attribute passed to whatever function in the controller that is being called. When there is no project I will use a reserved project name to specify a site wide project whose contents are visible from all projects. When there is a project it will be the first element in the URI, and that must be shifted to the right so that it is the first attribute in the controller functions.

The project names should not be hard coded because this data is in the database and it changes often. However, I can easily enforce rules to how the projects can be named.

What I want to know is, can the routing in CI be used for this, should I create my own routing class, or should I use a hook to intercept the URI data and fix it before CI's router sees it?

Why not skip the first segment using routing?
$route['[A-Z]+/(.*)'] = '$1';
Of course you need to limit the project names as much as possible to prevent a project name is the same as a controller.

Thank you, that works perfectly. I'm still learning how this routing feature works.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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