2013-12-16 110 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方法连接这个监听器,它应该做你要找的东西。

相关问题