Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find route of a current page?

Tags:

php

opencart

Is there a line of code that I can use in the controller that determines the route of a current page?

For example, I would like to find the route of the page with SEO url https://example.com/desktops (this should return the route product/category).

Similarly, url such as https://example.com/index.php?route=product/product&path=18&product_id=47 should return route as product/product.

like image 410
user1448031 Avatar asked Jun 26 '13 13:06

user1448031


People also ask

How do I find my current route URL?

Steps to get current route URL in Angular. Import Router,NavigationEnd from '@angular/router' and inject in the constructor. Subscribe to the NavigationEnd event of the router. Get the current route url by accessing NavigationEnd's url property.

How do you get the current page route in flutter?

When a button in the bottom bar is clicked, its current route path (/a/b/c) is saved and previously saved route is restored according to the button click. Conceptually user will think each button as a workspace and its state is never get lost (including back stack). User can safely switch from one workspace to another.

How do you find the current route in react?

Use the useLocation() hook to get the current route with React Router, e.g. const location = useLocation() . The hook returns the current location object. For example, you can access the pathname as location. pathname .

How can I get current route in laravel?

Accessing The Current RouteThe Route::current() method will return the route handling the current HTTP request, allowing you to inspect the full Illuminate\Routing\Route instance: $route = Route::current(); $name = $route->getName();


1 Answers

To be honest, the right answer is $this->request->get['route'];.

In order to catch the current route, you can use $this->request->get['route']; in the catalog/controller/common/header.php file in the index() function. Header.php is a part of practically any frontend output (as I understand, right now you are not sure what controller is used in http://example.com/desktops so you need right place where you can run your code in any case).

The SEO module does not unset this part of the request object. Also, keep in mind, in the middle of OpenCart code generation the $_GET array and the $this->request->get array is not the same things. You won't catch current route (in "path/controller/action" format) in $_GET superglobal php array when SEO module is in action, but you can catch it with any controller by using $this->request->get array which is prepared for you by OpenCart engine.

like image 113
Ronin Avatar answered Sep 28 '22 03:09

Ronin