Welcome Guest, Not a member yet? Register   Sign In
problem with routes
#1

[eluser]Bramme[/eluser]
Hey all,

I'm still working on porting a website I made to CI. I've finished up most of the front end, which is entirely based on one controller: page. I use routing to cut off the page/ part and just directly route to the function like this.
Code:
$route['(:any)'] = "page/$1";

But now I'm starting on the backend and it seemed only right to me to create a new controller for it. So I made a new controller, Admin. I thought I could set up routes like this:
Code:
$rout['admin'] = 'admin';
$route['(:any)'] = "page/$1";

and I'd be good to go, but that's clearly not the case, as I'm getting a CI 404.

Code:
$rout['admin/(:any)'] = 'admin/$1';
$route['site/(:any)'] = "page/$1";
This works, but it's not exactly what I want... Any way to make the site/ part go away?

Any help?
#2

[eluser]Pascal Kriete[/eluser]
What is that supposed to do? (and you have a typo - missing an e in route).
#3

[eluser]Bramme[/eluser]
[quote author="inparo" date="1212706655"]What is that supposed to do? (and you have a typo - missing an e in route).[/quote]

Hmm, didn't notice the typo, fixed it but still a problem.

What I'm trying to do is this:

People browse the site like mysite.com/home/, mysite.com/guestbook/ etc etc, home, guestbook are all functions of my Page controller. But when you got to mysite.com/admin/ I want the browser to access the Admin controller, and not the Page controller.
#4

[eluser]Pascal Kriete[/eluser]
Ah, sorry I was too fast . Didn't see the site/ example. Since the routes are checked sequentially just removing the site/ should work (as long as it's last). Otherwise you could put the admin stuff in a folder.
Code:
$route['admin/(:any)'] = 'admin/$1';
$route['(:any)'] = "page/$1";
#5

[eluser]Bramme[/eluser]
Code:
$route['admin'] = 'admin';
$route['admin/(:any)'] = 'admin/$1';
$route['(:any)'] = "page/$1";

Now it's fully working. Without the first route mysite.com/admin/ went to the 404

Thanks for the help!
#6

[eluser]louis w[/eluser]
I am doing something similar. This is my route config:

Code:
// Route everything except admin calls to the site controller.
$route['admin/(.*)']    = "admin/$1";
$route['admin']         = "admin";
$route['(.*)']          = "site/$1";
#7

[eluser]xwero[/eluser]
the admin routes can be only one route if you do this
Code:
$route['admin(.*)'] = 'admin$1';
#8

[eluser]Bramme[/eluser]
.* means any character at least one time?
#9

[eluser]jasonjohnson[/eluser]
I'm fairly certain (.*) means any character zero or more times. (.+) is any character one or more times.
#10

[eluser]Pascal Kriete[/eluser]
Yup, but if you do make sure none of your other controllers start with 'admin' (i.e. admin_contact).




Theme © iAndrew 2016 - Forum software by © MyBB