0

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

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

提前致谢。

4

1 回答 1

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);
    }
}
于 2013-07-02T13:22:56.633 回答