如何找到当前页面的路线? [英] How to find route of a current page?

查看:127
本文介绍了如何找到当前页面的路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在控制器中使用一行代码来确定当前页面的路线吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆