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

[eluser]richzilla[/eluser]
Hi all, I've looked through the user guide, but it doesn't seem to make what i want to do very clear, or I'm missing something...

Basically i want to route a url with any function name to the same controller, but with the function name appended to the end. so for example in my site:

id want
Code:
/health-and-safety/courses
to route to
Code:
/hs/courses
and also
Code:
health-and-safety/home
to route to
Code:
hs/home

I can do it on the routes side of the statement with
Code:
/health-and-safety/:any
as the value for the route but how to i get the
Code:
:any
value to be copied onto the hs/ side?

Any help would be appreciated.
Thanks
#2

[eluser]Kosonome[/eluser]
You change the route /health-and-safety/home -> /hs/index/home, then you can make one more route /hs/index/home -> /hs/home.

Or you can make a regular expression. I guess that's the best way, since it gives me headaches (I'm not good with them yet Sad ).
#3

[eluser]richzilla[/eluser]
Thanks for the help. Yea, i thought about doing that, but the health and safety section might have 20 pages eventually, so im trying to avoid hard coding routes for every page, what i want is for it to basically replace the
Code:
health-and-safety/
part with
Code:
hs/
#4

[eluser]tomcode[/eluser]
Put these two lines in Your config/routes.php :

Code:
$route['health-and-safety'] = 'hs';
$route['health-and-safety/(:any)'] = 'hs/$1';

Now all requests for health-and-safety end in the controller hs.




Theme © iAndrew 2016 - Forum software by © MyBB