在 prestashop 中获取当前页面和 url
Get current page and url in 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 以构成页面的当前 url?
无需手动重构link,可以使用Linkclass.
// 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);
我正在尝试获取 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?
无需手动重构link,可以使用Linkclass.
// 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);