开发者

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()
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜