可能是一個荒謬的問題,但是有沒有從控制器類本身獲取實際控制器名稱的方法?從控制器本身獲取控制器名稱
像
class SomeController extends Zend_Controller_Action {
public function init() {
$controllerName = $this -> getControllerName();
// And get "Some" as a output
}
}
可能是一個荒謬的問題,但是有沒有從控制器類本身獲取實際控制器名稱的方法?從控制器本身獲取控制器名稱
像
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();
}
哇,看起來很多要求。它是否加起來與網站的性能? – mrN
您可以要求使用getControllerName()
得到控制器的名稱。要獲得請求(無單例),您可以執行以下操作:
public function init() {
$controllerName = $this->_request->getControllerName();
// or
$controllerName = $this->getRequest()->getControllerName();
// or
$controllerName = $this->getFrontController()->getRequest()->getControllerName()
}
最佳答案!爲我工作! – Abadis
like get_class($ this)? – Rufinus
@Rufinus,正好! :) – mrN