ZF2-400: ViewJsonStrategy

Issue Type: Bug Created: 2012-07-16T17:45:04.000+0000 Last Updated: 2012-07-24T23:20:12.000+0000 Status: Resolved Fix version(s): Reporter: Sammie S. Taunton (diemuzi) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\Json

  • Zend\View
  • JsonModel

Related issues: Attachments:


I can't find exactly what changed in Beta 5 but in Beta 4 this worked great, now it appears to be broken.

I'd like to use the ViewJsonStrategy via JsonModel(). Using the example that worked in Beta 4 found here ->…

However, the problem here is as of Beta 5 when you add the following to the view_manager in ANY module config/module.config.php file it breaks ALL modules: 'strategies' => array('ViewJsonStrategy')

The results you get are: {"content":[]}

I thought perhaps I was doing something wrong so I returned to Beta 4 and recreated the Skeleton App and added the ZF2 library and it worked. So I decided to go back to Beta 5 and do the exact same thing by cloning the most up2date SkeletonApp and ZF2 Library and the problem exists here.

If you have any additional modules, the {"content":[]} will also show up on those modules too, it's not just contained within a single module. So it renders your entire application void until you remove the 'strategies' => array('ViewJsonStrategy') from the view_manager.

If something did change in Beta 5 that would help resolve this I'd love to know how to go about making it work again.


Posted by Thomas Lhotta (thomaslhotta) on 2012-07-18T11:24:26.000+0000

I can confirm this. The ViewJsonStrategy will always be selected, regardless of what view model is returned in the controller. The check for the accept header doesn't work with Firefox because it adds / to the accept header.

Posted by Adam Lundrigan (adamlundrigan) on 2012-07-19T11:52:15.000+0000

I have experienced this as well ( It is a known issue that is being worked on (ref:…)

Posted by Sammie S. Taunton (diemuzi) on 2012-07-24T23:20:12.000+0000

Resolved with:

will only choose JsonStrategy for application/json or application/javascript

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.