ZF2-183: Zend\View\Renderer\JsonRenderer -> recurseModel() returns Zend\View\Variables instead of an array

Issue Type: Bug Created: 2012-03-01T05:05:00.000+0000 Last Updated: 2012-06-14T21:10:35.000+0000 Status: Resolved Fix version(s): Reporter: Roman Vidyayev (cmple) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\View

  • JsonRenderer
  • json
  • view

Related issues: Attachments:


<pre class="highlight">
 * Retrieve values from a model and recurse its children to build a data structure
 * @param  Model $model 
 * @return array

The recurseModel(Model $model) function in Zend\View\Renderer\JsonRenderer does not return an array. instead it returns:

<pre class="highlight">
Zend\View\Variables Object
    [strictVars:protected] => 
    [storage:ArrayObject:private] => Array
            [content] => Array
                    [test] => json



<pre class="highlight">
class Module implements AutoloaderProvider {

    public function init(Manager $moduleManager) {
        $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');
        $jsonStrategy = $locator->get('Zend\View\Strategy\JsonStrategy');

    public function initializeView($e) {
                $app = $e->getParam('application');
                $basePath = $app->getRequest()->getBasePath();
                $locator = $app->getLocator();
                $renderer = $locator->get('Zend\View\Renderer\PhpRenderer');

<pre class="highlight">
class UserController extends ActionController {

    public function indexAction() {
        return array('json' => 'test');


Posted by Frank Br├╝ckner (frosch) on 2012-03-01T11:26:11.000+0000

Code tags added.

Posted by Roman Vidyayev (cmple) on 2012-03-01T17:34:48.000+0000

Added testing code

Posted by Matt Kynx (kynx) on 2012-04-22T16:21:38.000+0000

It looks like this has been fixed in recent git versions, though it still outputs the view's 'captureTo' as a key if the controller returns a normal ViewModel (ie something like {'content':{'json':'test').

Returning a JsonModel works as expected (it's got captureTo set to null), but that kind of defeats the purpose of overriding the renderer in the first place. See:

Posted by Maks 3w (maks3w) on 2012-06-14T21:10:35.000+0000

According to the comments this issue is fixed

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.