JsonModel 返回 children、选项和模板

JsonModel returning children, options and templates

我正在使用 Zend Framework 2 和 Angular.js 开发应用程序。

我有一个 Rest API 模块,也使用一个标准模块 returning JsonModel 更具体的东西(问题出在那里)。

在我的 module.config.php 中,我这样配置 view_manager:

'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions'       => true,
'doctype'                  => 'HTML5',
'not_found_template'       => 'error/404',
'exception_template'       => 'error/index',
'template_map' => array(
    'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
    'portal/index/index' => __DIR__ . '/../view/portal/index/index.phtml',
    'error/404'               => __DIR__ . '/../view/error/404.phtml',
    'error/index'             => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
    __DIR__ . '/../view',
),
'strategies' => array(
    'ViewJsonStrategy'
)
),

如果我这样做之前:

...
return new JsonModel(array('teste'=>true));
...

return 是:

{"teste":true}

但是不知道什么原因,return现在是这样的:

{"children":[],"options":[],"template":"portal-admin\/transportadora\/verifica-cnpj-cadastrado","terminate":true,"variables":{"teste":true},"append":false}

我查看了 class 参考中的任何答案,但一无所获。

有人可以help-me?

谢谢。


编辑:我只想return "variables"。

已解决!

问题出在我的控制器上。

当您将控制器扩展到 AbstractRestFulController 时,return 将是这个(带有子项、模板、变量)。你只需要对待结果。

但在我的例子中,我扩展了错误的 class,我需要扩展 AbstractActionController 而不是 AbstractRestfulController。

所以结果不一样。

谢谢大家!