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

Hi there

Maybe someone can give me an advice in setting custom routes. What I'd like to achieve is the following:

Theres a controller called Blog.php

I want some URI to get directed to this controller, e.g.:

/place/info/files
/place/info/people

There's no controller Place. Instead Blog should be used but with the segments provided. I need to have the URI segments to be available in Blog.php.

Hm, I hope I was clear enough in what I am working on…

Thanks for any advice.
Reply
#2

PHP Code:
$route['place/(:any)'] = 'blog/$1'
Reply
#3

Thanks for your idea. I tried it and it works for URIs with a second segment. But if there are more than two segments, it doesn't work anymore…
Reply
#4

You can try something like this:

Code:
$route['login/(.+)'] = 'auth/login/$1';




This is will capture all segments after 'login'. 
I would be a bit hesitant to use it since if you have route that starts with the '/login' it will be overwritten. 

So the following construction will be automatically redirected to 'auth/login/$1'


Code:
$route['login/app] = 'auth/app/$1';
Reply
#5

Any route that contains (:any) or (.+) should be the very last route.

This is because they are a catch all route, so place them after all other routes.

Then you will not over write or have problems with your routing.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(05-27-2019, 01:07 PM)bastian Wrote: Thanks for your idea. I tried it and it works for URIs with a second segment. But if there are more than two segments, it doesn't work anymore…

If I understand it well, I think you should try:

PHP Code:
$route['place/info/(:any)'] = 'blog/$1'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB