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

[eluser]rufisgumbo[/eluser]
I have a controller named <b>controllers/contact.php</b>

I want to load this controller using either of these URLS:

website.com/contact
website.com/members/contact

So I put this in routes.php:

Code:
$route['members/contact/(:any)'] = 'contact/$1';

Yet if I load /members/contact now, it just returns a 404. What am I missing?
#2

[eluser]John_Betong_002[/eluser]
Try this:

Code:
$route["members/contact"]        = "contact";      // defaults to index()
$route["members/contact/(:any)"] = "contact/$1";   // looks for a $1 method
&nbsp;
#3

[eluser]Aken[/eluser]
John's code might work, but you should always define the most specific routes first, so they are picked up in the proper order.
Code:
$route['members/contact/(:any)'] = 'contact/$1';
$route['members/contact'] = 'contact';

If you don't have any other functions in your contact controller, and will only need to use that controller from one of the two URLs mentioned, you can avoid the :any part.
Code:
$route['members/contact'] = 'contact';
#4

[eluser]rufisgumbo[/eluser]
Thanks guys, working.




Theme © iAndrew 2016 - Forum software by © MyBB