简体   繁体   English

如何在 OpenCart .tpl 文件中获取当前 url?

[英]How to get the current url in a OpenCart .tpl file?

I'd like to get the current url in a .tpl file in OpenCart.我想在 OpenCart 的 .tpl 文件中获取当前 url。

I've seen this answer but it works only in a php file.我见过这个答案,但它只适用于 php 文件。

I have to get this way:我必须这样:

_my_array.push(['_productName',"<?php echo $heading_title; ?>"]);
**_my_array.push(['_productUrl', ["how can I get url ?"]]);**

Thanks谢谢

To get full url获取完整网址

<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>

and btw those answers work on tpl files also because tpl files are sort of php files only顺便说一句,这些答案也适用于 tpl 文件,因为 tpl 文件只是一种 php 文件

The best practice would be to get it in the controller then use it in the view file.最佳做法是将其放入控制器中,然后在视图文件中使用它。

In your controller在您的控制器中

$data['current'] = $this->url->link($this->request->get['route'], '', 'SSL');

Then in the view file然后在视图文件中

echo $current;

I also needed current url for schema.org.我还需要 schema.org 的当前 url。

Generally you can create current url via link function通常您可以通过链接功能创建当前网址

public function link($route, $args = '', $secure = false)

So https link for product page that would be因此,产品页面的 https 链接将是

$data['share'] = $this->url->link('product/product', 'product_id=' . (int)$this->request->get['product_id'], true);

Then in the view file然后在视图文件中

echo $share

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM