Zend Framework : Detecting which controller or page you are using / are on

淺唱寂寞╮ 提交于 2019-12-23 02:18:57

问题


I'm trying to detect which controller I'm using or what controller I'm on and then change my menu accordingly to the page I'm on.

( Make a selection in the menu so the user can see were he is on the page! )

I really don't know what to write to check what it's using...

<? if($this->url(array("controller" => "index", "action" => "index"), null, true)) {
    echo("LOL");
}
?>

I tried that but that stuff didn't work at all, I know it's the wrong thing to use, so please help me =D


回答1:


You can get Controller and Action name from the current Request object with getControllerName() and getActionName().

From your controller:

$controller = $this->getRequest()->getControllerName();
$action = $this->getRequest()->getActionName();
// set to View

From a ViewHelper

$front = Zend_Controller_Front::getInstance();
$controller = $front->getRequest()->getControllerName();
$action = $front->getRequest()->getActionName();
// do something with it


来源:https://stackoverflow.com/questions/3361736/zend-framework-detecting-which-controller-or-page-you-are-using-are-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!