【问题标题】:Get current page and url in prestashop在 prestashop 中获取当前页面和 url
【发布时间】:2015-09-30 03:20:31
【问题描述】:
我试图在 prestashop 中获取当前页面的 url 以测试网站的多个页面,即使网站页面没有一致的模式。我注意到大多数 prestashop 页面的格式为 /index.php?id_category=<categoryid>&controller=<controllername>, /index.php?id_product=<productid>&controller=<controllername> 等。我可以使用获取控制器名称
Context::getContext()->controller->php_self
那么,我想知道如何获取产品 id 或类别 id 来形成页面的当前 url?
【问题讨论】:
标签:
php
model-view-controller
controller
seo
prestashop
【解决方案1】:
无需手动重构链接,使用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);