How to get Current Controller name in prestashop?
Asked Answered
K

5

6

How do I get the Current Controller name in prestashop 1.5?

Kotto answered 31/12, 2012 at 5:57 Comment(1)
Tools::getValue('controller') is the correct answer even for v1.6Photoreceptor
C
9

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

See detailed documentation here.

Cess answered 8/11, 2013 at 11:1 Comment(0)
C
7

Try to using it: Context::getContext()->controller

Cellobiose answered 2/1, 2013 at 9:53 Comment(2)
Context::getContext()->controller->php_selfDani
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
S
6

a straight forward solution

$controller_name = Tools::getValue('controller');
Shebat answered 27/2, 2014 at 21:29 Comment(2)
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()->controllerShebat
I
2

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));

Indecorous answered 2/1, 2013 at 10:40 Comment(0)
E
0

The easiest and cleanest way is with

$this->controller_name
Edmanda answered 17/6, 2020 at 4:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.