Welcome Guest, Not a member yet? Register   Sign In
Routing question
#1

[eluser]mrtopher[/eluser]
I'm in the process of developing a hosted content management system. The concept I have in my head is that there will be 1 single CI application so that both the front end (which serves up the users websites) and admin area (which users use to modify their sites) can share files.

I have placed the controllers for the admin area in a sub folder inside controllers called admin. So, when a user visits http://www.somesite.com/any-page-name I need it to route through the display controller I have created. But, if the user visits http://www.somesite.com/admin/* then I need it to look in controllers/admin for the appropriate controller.

In my mind this type of configuration is represented with the following:
Code:
$route['default_controller'] = "display";
$route['scaffolding_trigger'] = "";

$route['admin'] = 'admin/dashboard';
$route['admin/websites/:any'] = 'admin/websites';

$route[':any'] = 'display';

But that doesn't work. When I visit http://www.somesite.com/admin the default controller (admin/dashboard in this case) is served up, but if I place anything after admin like http://www.somesite.com/admin/dashboard I get a CI 404 error.

Anyone have any ideas on how I can accomplish this?
#2

[eluser]louis w[/eluser]
I have something almost identical, this is what I have in my routes:

Code:
$route['admin/(.*)']         = 'admin/$1';
$route['admin']         = 'admin/admin';

$route['(.*)']              = "site/$1";

My directory structure is a little different thou because I needed admin to be made up of a bunch of different controllers. So if you go to /admin it will route to the admin controller in the admin folder, but if you go to /admin/users it would map to the users controller in the admin folder. All requests outside of admin are mapped to my Site controller. You probably don't need to pass the url into Site if you don't want to like I am.

Code:
- Controllers
   - Site
   - Admin (Directory)
       - Admin
       - Whatever

Hope this helps.
#3

[eluser]mrtopher[/eluser]
louis w: that's perfect! Just what I was looking for.

Now, however, I have another problem. I have a controller in the admin folder called websites and I would like all requests to the websites controller processed to the index function. I've expressed that using the following in the routes file:

Code:
$route['admin/websites/(.*)'] = 'admin/websites/index';

Any request I make to the websites controller now returns a CI 404 error. I can bring up /admin/websites/index without trouble, but anything else returns an error.

I also tried the following and got the same result.

Code:
$route['admin/websites/:any'] = 'admin/websites/index';

Any ideas?
#4

[eluser]louis w[/eluser]
You shouldn't need to do anything to point it at the index method, CI by default will call this as the default option.

Try removing what you have, does it work?

If not, add a _remap method to your controller and just do an echo in it. Does that work?

Because of the wildcard in the first route - the (*.) - you dont need anything beyond what I have to call any controller in the admin directory.
#5

[eluser]mrtopher[/eluser]
Never mind, found the solution myself.

I just created a _remap() function in the websites class and removed the custom route all together.

Thanks again for the help!




Theme © iAndrew 2016 - Forum software by © MyBB