Get current controller

in the function I want to reach the current controller:

$front = Zend_Controller_Front::getInstance(); 

this only gives the handler, but not the current controller.

I changed the code from the function to the internal controller. and asked their origin as the handler I received 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 achieve a real initial frontal controller?

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

+4
source share
2 answers
 Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); 
+7
source

Possible with:

 $front = Zend_Controller_Front::getInstance() $request = $front->getRequest(); $module = ucfirst($request->getModuleName()); $controller = ucfirst($request->getControllerName()); $instance = new $module . '_' . $controller . 'Controller'; 

In the action helper:

 $instance = $this->getActionController(); 

But , this probably means that something is wrong with your architecture. You must move the generic code needed for the action assistant, service, or model.

+1
source

All Articles