2013-07-02 97 views

回答

1

檢查創建和註冊備用渲染和響應策略。 http://framework.zend.com/manual/2.0/en/modules/zend.view.quick-start.html#creating-and-registering-alternate-rendering-and-response-strategies

namespace Application;

class Module 
{ 
    public function onBootstrap($e) 
    { 
     // Register a "render" event, at high priority (so it executes prior 
     // to the view attempting to render) 
     $app = $e->getApplication(); 
     $app->getEventManager()->attach('render', array($this, 'registerJsonStrategy'), 100); 
    } 

    public function registerJsonStrategy($e) 
    { 
     $app   = $e->getTarget(); 
     $locator  = $app->getServiceManager(); 
     $view   = $locator->get('Zend\View\View'); 
     $jsonStrategy = $locator->get('ViewJsonStrategy'); 

     // Attach strategy, which is a listener aggregate, at high priority 
     $view->getEventManager()->attach($jsonStrategy, 100); 
    } 
}