Welcome Guest, Not a member yet? Register   Sign In
alternative name for controller using routes
#1

[eluser]gRoberts[/eluser]
Hi all,

I've nearly finished a web site i've been working on for 3 months now (THANK GOD) and the client has requested that I rename two controllers.

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$route['signin'] = '/user/login';
$route['signout'] = '/user/logout';
$route['signup'] = '/user/signup';
$route['contact'] = '/home/contact';
$route['about'] = '/home/about';
$route['faq'] = '/home/faq';
$route['terms'] = '/home/terms';
$route['privacy'] = '/home/privacy';
$route['invite'] = '/my/friends/invite';
$route['sitemap'] = '/home/sitemap';

$route['(blog|categories|collectors|csv|ebay|external|home|items|my|tags|tools|user|groups)(.+)?'] = '$1$2';

$route[':any'] = "user/view/$1";

Here are the routes I currently have setup. This works great.

Now i'd like to add an route which will forward all requests from one controller to another. This way, things dont get messy.

I have tried adding

Code:
$route['blogs/:any'] = '/blog/$1';
$route['collectibles/:any'] = '/items/$1';

But that gives me an 404 when I try using the new name.

I then tried

Code:
$route['blogs(.+)?'] = '/blog$1';
$route['collectibles(.+)?'] = '/items$1';

Which worked but didn't pass any of my parameters to my functions.

Does anyone have any idea why?

Thank you all in advance!
#2

[eluser]Phil Sturgeon[/eluser]
The first example is wrong as you are mixing the CI style identifiers with reqular expression identifiers. The second is bust as you are not actually sending it to a controller, you need to have the value (the string on the right) as the ACTUAL controllers its going to.

Code:
$route['collectibles(.+)?'] = 'items/thing/$1';
#3

[eluser]gRoberts[/eluser]
I'm not sure i understand what you mean.

Basically i need to forward any requests to collectibles to items ie

www.domain.com/collectibles/view/3
to
www.domain.com/items/view/3

but without having to manually handle each and every function within the controller.
#4

[eluser]Phil Sturgeon[/eluser]
I used the method name "thing" as I had no way of knowing what it was, figured you would swap it out with your actual method.

Code:
$route['collectibles(.+)?'] = 'items/view/$1';

This route uses an actual CI path on the right, controller, method, param. The CI paths you were using were invalid as they had none of the right segments.
#5

[eluser]gRoberts[/eluser]
I understand that, but I need to do it for all methods, not just one.

Surely I should be able to call the items controller with any thing that is sent to the collectibles?

ie

www.domain.com/collectibles/view/1

I should be able to now use /view/1 and pass it to items which would produce the same result as if I had gone to

www.domain.com/items/view/1
#6

[eluser]Elliot Haughin[/eluser]
Code:
$route['blogs'] = 'blog';
$route['blogs/(.*)'] = 'blog/$1';
$route['collectibles'] = 'items';
$route['collectibles/(.*)'] = 'items/$1'

Give this a go... let me know if it works.
#7

[eluser]gRoberts[/eluser]
:coolhmm:

Smooooooth. Thanks thats exactly what i need, or at least I think it is, I've just noticed a slight issue with some code which could be due to the routing or it could be just me.

Thank you !

Pyro - Thank you for your effect, I appreciate it.
#8

[eluser]Elliot Haughin[/eluser]
Well, there's no semi-colon on the end of the last route that I posted....
If you've just copied and pasted them routes, change:

Code:
$route['collectibles/(.*)'] = 'items/$1'

to

Code:
$route['collectibles/(.*)'] = 'items/$1';
#9

[eluser]Phil Sturgeon[/eluser]
Glad you have this solved, although I am wondering if it would be eaiser for you to simply physically rename the controllers with a bit of Find & Replace spam.
#10

[eluser]gRoberts[/eluser]
The site is mahoosive (big) and i have a mixture of CS urls (site_url) and static urls. Renaming them would be tedious one by one, and if I do a find/replace globally, I could end up renaming php content I shouldn't which is why I went down this route first.




Theme © iAndrew 2016 - Forum software by © MyBB