如何找到当前页面的路线? [英] How to find route of a current page?
问题描述
我可以在控制器中使用一行代码来确定当前页面的路线吗?
Is there a line of code that I can use in the controller that determines the route of a current page?
例如,我想使用SEO URL https://example.com/desktops
查找页面的路由(这应该返回路由product/category
).
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
).
类似地,诸如https://example.com/index.php?route=product/product&path=18&product_id=47
之类的url应该将路由返回为product/product
.
Similarly, url such as https://example.com/index.php?route=product/product&path=18&product_id=47
should return route as product/product
.
推荐答案
老实说,正确的答案是$this->request->get['route'];
.
To be honest, the right answer is $this->request->get['route'];
.
为了捕获当前路线,可以在index()
功能的catalog/controller/common/header.php
文件中使用$this->request->get['route'];
. Header.php
实际上是任何前端输出的一部分(据我了解,现在您不确定http://example.com/desktops
使用的是哪个控制器,因此需要在任何情况下都可以运行代码的正确位置).
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).
SEO模块不会取消设置请求对象的这一部分.另外,请记住,在OpenCart代码生成的中间,$_GET
数组和$this->request->get
数组是不同的东西. SEO模块运行时,您不会在$ _GET超全局php数组中捕获当前路由(以路径/控制器/操作"格式),但是您可以使用为您准备的$this->request->get
数组与任何控制器一起捕获它通过OpenCart引擎.
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.
这篇关于如何找到当前页面的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!