首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Symfony2 FOSRestBundle handleView()不工作

Symfony2 FOSRestBundle handleView()不工作
EN

Stack Overflow用户
提问于 2016-03-16 14:34:11
回答 1查看 1.1K关注 0票数 3

刚刚用symfony2创建了一个新项目并安装了FOSRestBundle。控制器示例:

代码语言:javascript
运行
复制
<?php

namespace ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\FOSRestController;


class TestController extends FOSRestController
{
    public function TestAction()
    {
        $data = array ('1', '2', '3', 'four'); // get data, in this case list of users.
        $view = $this->view($data, 200)
            ->setTemplate("ApiBundle:Test:test.html.twig")
            ->setTemplateVar('test')
        ;

        return $this->handleView($view);       
    }

}

收到错误消息:

代码语言:javascript
运行
复制
You have requested a non-existent service "fos_rest.view_handler".

有人知道这件事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-16 14:45:50

在您的AppKernel中,请确保有以下内容:

代码语言:javascript
运行
复制
// app/config/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\RestBundle\FOSRestBundle(),
    );
}

你肯定忘了这一步

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36038728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档