Arc*_*rma 3 php model-view-controller seo controller prestashop
我想在prestashop中获取当前页面的url来测试网站的多个页面,即使网站页面没有一致的模式.我注意到大多数prestashop页面都是格式/index.php?id_category=<categoryid>&controller=<controllername>, /index.php?id_product=<productid>&controller=<controllername>等.我能够使用控制器名称
Context::getContext()->controller->php_self
所以,我想知道如何获取产品ID或类别ID以形成页面的当前网址?
小智 8
无需手动重建链接,您可以使用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);
Run Code Online (Sandbox Code Playgroud)