How do I get the Current Controller name in prestashop 1.5?
How to get Current Controller name in prestashop?
Asked Answered
Tools::getValue('controller') is the correct answer even for v1.6 –
Photoreceptor
In your smarty template file (.tpl) use this code to get controller name.
{* Example URL Example.com/index.php?id_category=4&controller=category}
{assign var='controllerName' value=$smarty.get.controller}
{$controllerName}
OR
{$smarty.get.controller}
Smarty have reserved variables
Try to using it: Context::getContext()->controller
Context::getContext()->controller->php_self
–
Dani I've found that
Context::getContext()->controller->php_self
isn't always defined. It is sometimes and fitted my needs but you should check if it isset()
before using it. –
Kharif a straight forward solution
$controller_name = Tools::getValue('controller');
This one is the way also used in Dispatcher->getController() so should be the best one, thank you. –
Photoreceptor
You could also get it like this Context::getContext()->controller –
Shebat
get_class($this) or write it in your front controller and you will have controller name in all of your tpl files self::$smarty->assign('currentController', get_class($this));
The easiest and cleanest way is with
$this->controller_name
© 2022 - 2024 — McMap. All rights reserved.