get current controller

无人久伴 提交于 2019-12-04 13:30:10

问题


in a function I want to reach current controller:

$front = Zend_Controller_Front::getInstance();

this only gives a handler but not current controller.

I changed the code from function to inside of controller. and asked their origins both the handler I got from getInstance and this

var_dump(get_class($front), get_class($this));

I get:

string 'Zend_Controller_Front' (length=21)
string 'IndexController' (length=15)

How can I reach real initiated front controller?

I cant pass as a parameter, because this function is used trillion times.


回答1:


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



回答2:


Possible with:

$front = Zend_Controller_Front::getInstance()
$request = $front->getRequest();
$module = ucfirst($request->getModuleName());
$controller = ucfirst($request->getControllerName());

$instance = new $module . '_' . $controller . 'Controller';

In Action Helper:

$instance = $this->getActionController();

But, this probably means that's something wrong with your architecture.
You should move the common code you need to action helper, service or model.



来源:https://stackoverflow.com/questions/4345414/get-current-controller

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