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
}
}
public function init() {
echo Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
}
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()
}
精彩评论