2013-08-16 61 views

回答

2

創建一個實例您沒有訪問該服務經理這因爲它在對象被實例化時被注入。

你總是可以打動你的代碼被觸發onDispatch(),而不是在構造器:

/** 
* Execute the request 
* 
* @param MvcEvent $e 
* @return mixed 
* @throws Exception\DomainException 
*/ 
public function onDispatch(MvcEvent $e) 
{ 
    // do something here 
    // or you could use the events system to attach to the onDispatch event 
    // rather than putting your code directly into the controller, which would be 
    // a better option 

    return parent::onDispatch($e); 
} 

我只想用活動來連接你需要什麼永遠,而不是使用控制器

Module.php

/** 
* Initialize 
* 
* @param \Mis\ModuleManager 
*/ 
public function init(ModuleManager $manager) 
{ 
    $events = $manager->getEventManager(); 
    $sharedEvents = $events->getSharedManager(); 
    $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) { 
     /* @var $e \Zend\Mvc\MvcEvent */ 
     // fired when an ActionController under the namespace is dispatched. 
     $controller = $e->getTarget(); 
     $routeMatch = $e->getRouteMatch(); 
     /* @var $routeMatch \Zend\Mvc\Router\RouteMatch */ 
     $routeName = $routeMatch->getMatchedRouteName(); 

     // Attach a method here to do what you need 

    }, 100); 
} 
+0

儘管答案的年齡的事實,我想知道,一旦你在module.php的'//附上一個方法來做你所需要的'使用一些工作方法 如何獲得傳遞給目標控制器的結果/數據? – inckka

相關問題