2012-04-11 90 views
0

我必須檢測哪個控制器路由之前視圖腳本被調用(所以postDispatch()是不適當的)。獲取路由控制器Zend_Controller_Plugin

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

    // } 
} 
} 

如何訪問控制器的名稱?

乾杯

回答

0

的方法,您需要具有比視圖渲染器更高的優先級來註冊一個動作助手。

  1. 在你的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. 在應用/控制器/助理/ 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'; 
         } 
        } 
    } 
    
0

有趣的是你正在將Zech與Perch融合!

根據文檔getControllerName是Zend_Controller_Request_Abstract

+0

謝謝,但我想這不會解決它。請求變量只包含參數 – Jens 2012-04-11 09:44:45

+0

哦,但我想我錯了。只有在丟失的Action被路由後才調用ErrorController。我對嗎? :/ – Jens 2012-04-11 09:45:37