Welcome Guest, Not a member yet? Register   Sign In
Get information about which route was used
#1

Hi,

Is this possible (in a controller) to find out which route was used? For example I have these  routes:


PHP Code:
$route['admin/projects_management/ajax_action'] = 'admin_projects_management/ajax_action';


$route['admin/projects_management/(:any)'] = 'admin_projects_management/index/$1'


User enters "admin/projects_management/122'" and now I would like to know that the second route ( 'admin/projects_management/(:any)'  ) was used. Is this possible?
Reply
#2

In your case you know allready what route you have uesed. If you are in the index method of your controller it comes from the second route. Anyhow there is no property to see, what route is used.

Reply
#3

(02-10-2015, 06:38 AM)Rufnex Wrote: In your case you know allready what route you have uesed. If you are in the index method of your controller it comes from the second route. Anyhow there is no property to see, what route is used.

Thanks.

If I wanted to modify router.php core class then where (at which line) should I look at, so I can accomplish this?
Reply
#4

You should never modify the core classes instead you have to extend the core as described here:

http://www.codeigniter.com/userguide3/ge...asses.html

Reply
#5

The real question is: why do you need to know what route was used? Whatever it is that you're trying to accomplish can probably be done another way. The router does have 3 public properties which expose most of the route information once it has been resolved (directory, class, and method). The URI segment method can tell you what URI segments were used for the current request.
Reply
#6

Let's try this:
http://www.codeigniter.com/userguide3/li...uri_string
Reply
#7

(02-10-2015, 06:44 AM)Rufnex Wrote: You should never modify the core classes instead you have to extend the core as described here:

http://www.codeigniter.com/userguide3/ge...asses.html

Yes, I know it, but I was in a hurrySmile I think I managed to do what I wanted in another way.



Quote:@mwhitney

The real question is: why do you need to know what route was used? Whatever it is that you're trying to accomplish can probably be done another way. The router does have 3 public properties which expose most of the route information once it has been resolved (directory, class, and method). The URI segment method can tell you what URI segments were used for the current request.

Well, I created a quite sophisticated i18 schema, that is, not only particular pages can be translated and user can switch between eg. 'en' and 'pl' version of the website (by switching it in URL)  - that was easy, but also links can be translated, so there are separate "en/contact" and "fr/nous_contacter" pages. 

I did this by playing with routes.

Anyway, it works now. Thanks for your answers.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB