Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting controller name from controller itself

Might be a ridiculous question, but Is there a way to get the actual controller name from the controller class itself?

like

class SomeController extends Zend_Controller_Action {
    public function init() {

         $controllerName = $this -> getControllerName();
         // And get "Some" as a output
    }
}
like image 586
mrN Avatar asked Jul 15 '11 08:07

mrN


2 Answers

public function init() {
   echo Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
}
like image 129
silex Avatar answered Nov 09 '22 01:11

silex


You can get controller name from request using getControllerName(). To get to the request (without singletons), you can do following:

public function init() {
    $controllerName = $this->_request->getControllerName();
    // or
    $controllerName = $this->getRequest()->getControllerName();
    // or
    $controllerName = $this->getFrontController()->getRequest()->getControllerName()
}
like image 25
Radek Benkel Avatar answered Nov 09 '22 01:11

Radek Benkel