简体   繁体   English

在prestashop中获取当前页面和网址

[英]Get current page and url in prestashop

I am trying to get the url of current page in prestashop to test multiple pages of a website even if the website pages do not have a consistent pattern. 我试图在prestashop中获取当前页面的URL以测试网站的多个页面,即使网站页面没有一致的模式。 I noticed that most of the prestashop pages are of the form /index.php?id_category=<categoryid>&controller=<controllername>, /index.php?id_product=<productid>&controller=<controllername> etc. I am able to get the controller name using Context::getContext()->controller->php_self 我注意到大多数prestashop页面的格式为/index.php?id_category=<categoryid>&controller=<controllername>, /index.php?id_product=<productid>&controller=<controllername>等。我能够得到控制器名称使用Context::getContext()->controller->php_self

So, I want to know how do I get the product id or category id to form the current url of a page? 所以,我想知道如何获取产品ID或类别ID以形成页面的当前网址?

There's no need to manually reconstruct the link, you can use the Link class. 无需手动重建链接,您可以使用Link类。

// Context
$context = Context::getContext();
// Category id (on category and product page)
$cid = $context->controller->getCategory()->id;
// Product id (on product page)
$pid = $context->controller->getProduct()->id;

// Category link
$cat_link = $context->link->getCategoryLink($cid);
// Product link
$prod_link = $context->link->getProductLink($pid);

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

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