module.config.php:

   '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',
            'index/index'   => __DIR__ . '/../view/index/index.phtml',
            'error/404'     => __DIR__ . '/../view/error/404.phtml',
            'error/index'   => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            'application' => __DIR__ . '/../view',
        ),
        //注意添加这个选项
        'strategies' => array(
            'ViewJsonStrategy',
        ),
    ),

controller:

function xxAction()
{
   return new JsonView(array('test'=>test));
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注