dongying6179 2012-04-11 09:33
浏览 15
已采纳

在Zend_Controller_Plugin中获取路由控制器

I have to detect which Controller is routed before the view script is called (so postDispatch() isn't appropriate).

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';

    // }
}
}

How can I access the name of the Controller?

Cheers

  • 写回答

2条回答 默认 最新

  • dousheng3364 2012-04-11 10:58
    关注

    You need to register an action helper with a higher priority than the view renderer.

    1. In your 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());
          }
      }
      
    2. In 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';
              }
          }
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题