0

I would like set all actions because when these return a ViewModel class, this has the parameter setTerminal = true by default.

I want that my aplication have this behavior because the 90% of my calls are AJAX.

Thanks in advance.

chrislondon
  • 12,487
  • 5
  • 26
  • 65
josepmra
  • 617
  • 9
  • 25

1 Answers1

1

Check the Creating and Registering Alternate Rendering and Response Strategies. 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);
    }
}
Haver
  • 443
  • 2
  • 11