Zend Framework 2默认情况下没有布局

时间:2013-07-02 11:39:35

标签: php zend-framework2 viewmodel zend-view zend-layout

我想设置所有操作,因为当它们返回一个ViewModel类时,默认情况下它的参数setTerminal = true。

我希望我的应用程序有这种行为,因为我的90%的调用都是AJAX。

提前致谢。

1 个答案:

答案 0 :(得分:1)

检查创建和注册备用渲染和响应策略。 http://framework.zend.com/manual/2.0/en/modules/zend.view.quick-start.html#creating-and-registering-alternate-rendering-and-response-strategies

命名空间应用程序;

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);
    }
}