2016-04-17 26 views
0

我很難從service-manager檢索使用zend-db調試對象。Zend調試不輸出服務定位器

我有在onBootstrap事件下面的代碼模塊:

public function onBootstrap(MvcEvent $e) 
    $eventManager = $e->getApplication()->getEventManager(); 
    $moduleRouteListener = new ModuleRouteListener(); 
    $moduleRouteListener->attach($eventManager);   
    $translator = $e->getApplication()->getServiceManager()->get('translator'); 
    $translator->setLocale(\Locale::acceptFromHttp($request->getServer('HTTP_ACCEPT_LANGUAGE'))) 
       ->setFallbackLocale(System::config('i18n/fallback_language')); 
    \Zend\Debug\Debug::dump($translator);   
    die(); 
} 

我不明白爲什麼,但由於某些原因,當我通過翻譯器來調試它清空了屏幕和執行暫停。 有趣的是,在這個階段使用其他對象似乎也是一個問題。

我不太確定這裏發生了什麼事。

我知道這些對象是有效的創建對象,因爲應用程序可以工作,但由於某種原因,我無法從服務定位器調試轉儲任何東西。

這是我的ini設置列表,以防萬一它與php設置有關。

Environment::iniSet('max_execution_time',0); 
Environment::iniSet('display_errors','1'); 
Environment::iniSet('display_startup_errors',1); 
Environment::iniSet('ignore_user_abort',1); 
Environment::iniSet('date.timezone','America/New_York'); 
Environment::iniSet('mime_magic.magicfile',1); 
Environment::iniSet('zend.ze1_compatibility_mode',0); 

任何幫助表示讚賞。

+1

某些對象具有遞歸依賴關係,因此無法顯示。 – akond

回答

0

我認爲你應該考慮使用一些mvc事件來附加你的(翻譯器)服務。舉例來說,您希望在控制器內或渲染過程中進行翻譯,然後獲取MvcEvent::EVENT_DISPATCH('dispatch')事件或MvcEvent::EVENT_RENDER('render')事件,並在該事件觸發時附加翻譯器。

你可以這樣說:

/** 
* @param EventInterface|MvcEvent $event 
*/ 
public function onBootstrap(EventInterface $event) 
{ 
    $application = $event->getApplication(); 
    $eventManager = $application->getEventManager(); 

    // Attach translator on dispatch Event 
    $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'attachTranslator')); 
} 

/** 
* @param MvcEvent $event 
*/ 
public function attachTranslator(MvcEvent $event) 
{ 
    $application = $event->getApplication(); 
    $serviceManager = $application->getServiceManager(); 
    $translator  = $serviceManager->get('translator'); 
    //do something with your translator 
} 

這樣你確保你只得到了翻譯,當你需要它(在調度或渲染),你確保你得到這一切之前,應用程序引導已完成...

+0

這太好了。感謝您的信息 – slicks1

+0

雖然它與問題無關。我只是說這很棒,因爲我是ZF2的新手,這很棒。我的問題是爲什麼我無法調試翻譯器對象 – slicks1

+0

@ slicks1好吧。我認爲它解決了你的問題... – Wilt