我必须在调用视图脚本之前检测哪个Controller 被路由(因此postDispatch()不合适)。
class PerchProvider extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
//if (--CONTROLLERNAME-- != "Error") {
include APPLICATION_PATH . '/../public/perch/runtime.php';
// }
}
}
如何访问Controller的名称?
干杯
答案 0 :(得分:0)
有趣的是你将鲈鱼与Zend整合!
根据文档,getControllerName是Zend_Controller_Request_Abstract上的一个方法
答案 1 :(得分:0)
您需要注册一个优先级高于视图渲染器的操作助手。
在你的Bootstrap.php中:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPerch()
{
require APPLICATION_PATH . '/controllers/helpers/Perch.php';
Zend_Controller_Action_HelperBroker::getStack()->offsetSet(2,
new Application_Controller_Helper_Perch());
}
}
在application / controllers / helpers / Perch.php中:
<?php
class Application_Controller_Helper_Perch
extends Zend_Controller_Action_Helper_Abstract
{
public function postDispatch()
{
$request = $this->getActionController()->getRequest();
$controller = $request->getControllerName();
if ($controller != 'error') {
include APPLICATION_PATH . '/../public/perch/runtime.php';
}
}
}