spr*_*ain 6 symfony fosrestbundle
我正在尝试关注如何使用Symfony2设置一个好的REST API的Will Durand教程.但是,当我收到此错误时,我在一开始就失败了:
The controller must return a response (Array(welcome => Welcome to my API) given).
Run Code Online (Sandbox Code Playgroud)
我的基本配置基本必须是错误的.我已经尝试了不同的fos_rest
配置设置,但配置参考并没有提供非常有用,因为我真的不明白单个设置的作用.
我的设置:
//config.yml
sensio_framework_extra:
view:
annotations: true
fos_rest: ~
Run Code Online (Sandbox Code Playgroud)
//Controller
<?php
namespace Acme\Bundle\ApiBundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
class DefaultController
{
/**
* @Rest\View
*/
public function indexAction()
{
return array(
'welcome' => 'Welcome to my API'
);
}
}
Run Code Online (Sandbox Code Playgroud)
我的API应该基于accept标头返回XML或者JSON.永远不会有html输出.
spr*_*ain 28
我修好了它!配置需要如下所示:
sensio_framework_extra:
view:
annotations: false
fos_rest:
view:
view_response_listener: true
Run Code Online (Sandbox Code Playgroud)