2013-12-16 148 views
0

如何禁用特定控制器中的ZF2開發人員工具?禁用Zend開發人員工具

我已經試過返回一個終端ViewModel,但它仍然呈現。

+0

爲什麼不只是在你的config.php文件夾中禁用它們? – cptnk

+0

我不想全局禁用它。 –

回答

3

您可以創建自己的偵聽器,該偵聽器在基於特定控制器分離事件的zdt邏輯之前觸發。

<?php 
namespace Application\Listener; 

use Zend\EventManager\AbstractListenerAggregate; 
use Zend\Mvc\MvcEvent; 
use Zend\ServiceManager\ServiceLocatorInterface; 

class DetachZdtListener extends AbstractListenerAggregate 
{ 

    protected $listeners = array(); 

    protected $serviceLocator; 

    public function __construct(ServiceLocatorInterface $serviceLocator) 
    { 
     $this->serviceLocator = $serviceLocator; 
    } 

    public function attach(\Zend\EventManager\EventManagerInterface $events) 
    { 
     // Attach a listener to the finish event that has a priority sooner 
     // than the ZDT listener(s) 
     $this->listeners[] = $events->attach(MvcEvent::EVENT_FINISH, 
      array($this, 'onFinish'), -9499 
     ); 

    } 

    /** 
    * The method called when event is fired 
    * 
    * @param \Zend\Mvc\MvcEvent $e 
    */ 
    public function onFinish(MvcEvent $e) { 

     $controller = $e->getController(); 

     if ($controller === 'Application\Controller\SomeController') { 

      $sm = $this->serviceLocator; 

      $eventManager = $e->getApplication()->getEventManager(); 
      $sharedEventManager = $eventManager->getSharedManager(); 

      $eventManager->detachAggregate($sm->get('ZendDeveloperTools\FlushListener')); 
      $eventManager->detachAggregate($sm->get('ZendDeveloperTools\ProfilerListener')); 

      $sharedEventManager->clearListeners('profiler'); 
     } 
    } 

} 

那麼你就只需要在一個FO你的模塊的onBootstrap方法連接這個監聽器,它應該做你要找的東西。

相關問題