HHGAG wrote
> 
> You only need to return a JsonModel object... If you create a new module
> or not isn't relevant.
> 
Sorry I'm a little lost here, can you help with an example ?
Ideally I'd want it to be in a single module to not over complicate things

here is what I've got so far:

class Module implements AutoloaderProvider
{
        ...
    public function init(Manager $moduleManager)
    {
        $moduleManager->events()->attach('loadModules.post', array($this,
'modulesLoaded'));
        
        $events = StaticEventManager::getInstance();
        $events->attach('bootstrap', 'bootstrap', array($this,
'initializeView'), 100);
        $events->attach('bootstrap', 'bootstrap', array($this,
'initializeJsonView'));
    }
    
    public function initializeJsonView($e) {
                $app          = $e->getParam('application');
                $locator      = $app->getLocator();
                $view         = $locator->get('Zend\View\View');
                $jsonRendererStrategy = 
$locator->get('Zend\View\Strategy\JsonStrategy');
                
                $view->events()->attachAggregate($jsonRendererStrategy, 10); 
    }
    
    public function initializeView($e)
    {
                $app = $e->getParam('application');             
                $basePath = $app->getRequest()->getBasePath();
                $locator = $app->getLocator();
                $renderer = $locator->get('Zend\View\Renderer\PhpRenderer');
                $renderer->plugin('url')->setRouter($app->getRouter());
                $renderer->doctype()->setDoctype('HTML5');
                $renderer->plugin('basePath')->setBasePath($basePath);
    }
...

The part that I don't get is how the JsonStragegy activates on the front
end,
I'd like the same page produce a different view based on the parameter:
http://localhost/user/login*?format=json*
or
http://localhost/user/login*.json*

Thanks!


--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-contextSwitch-to-json-tp4418147p4426549.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to