php - Symfony2 FOSRestBundle handleView() 不起作用

标签 php symfony fosrestbundle

刚刚使用 symfony2 创建了一个新项目并安装了 FOSRestBundle。 Controller 示例:

<?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);       
    }

}

收到错误信息:

You have requested a non-existent service "fos_rest.view_handler".

有人对此有想法吗?

最佳答案

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

// app/config/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\RestBundle\FOSRestBundle(),
    );
}

你肯定忘了this step .

关于php - Symfony2 FOSRestBundle handleView() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36038728/

相关文章:

symfony - 如何从 PHP 预填充 EntityType 类型的字段

javascript - 设置测验系统

forms - Symfony Form 字符串的类型约束验证整数值

php - Symfony2 FOS Rest 捆绑路由 FileLoaderLoadException Controller

php - 带有 css 的圆形选择选项(PHP 可处理)?

php - $facebook->getSession() 在示例代码中返回 null。那样行吗?

php - MYSQL 对大表的低效计数

php - 使用 Symfony2 形式插入 1.6 i18n

php - 如何完全跳过 PayPal 付款确认页面?

symfony - FOS 休息包 : Can the response be gzipped?