【问题标题】:Symfony2 FOSRestBundle handleView() doesn't workSymfony2 FOSRestBundle handleView() 不起作用
【发布时间】:2016-03-16 14:34:11
【问题描述】:

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

<?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".

有人知道吗?

【问题讨论】:

    标签: php symfony fosrestbundle


    【解决方案1】:

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

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

    你肯定忘记了this step

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 2015-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多