简体   繁体   中英

How to get controller name and action name on view in Zend Framework?

I am trying this code:

Zend_Controller_Front::getInstance()->getRequest()->getControllerName()
Zend_Controller_Front::getInstance()->getRequest()->getActionName()

I get this error:

Zend_Controller_Front Class Not Found

I am giving answer on the basis of what i have get from your question it might be wrong but from my point of view I am giving this answer.

$action= $this->getEvent()->getRouteMatch()->getParam('action');

$controller= $this->getEvent()->getRouteMatch()->getParam('controller');

you can write this in controller and pass this variables in view model.

$view = new ViewModel(array('action' =>$action,'controller' =>$controller));
$view->setTemplate("tournamentview/index/getTeam.phtml");
return $view;

and you can access action and controller variable in view ie getTeam.phtml file.$action will give you the action Name and the $ controller will give you the alias of controller like 'TournamentView\\Controller\\Index' hope it will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM