我正在尝试关注如何使用Symfony2设置一个良好的REST API Will Durand's tutorial。不过,我在一开始我没有,因为我得到这个错误:控制器必须返回一个响应,数组给出
The controller must return a response (Array(welcome => Welcome to my API) given).
一些基本的东西肯定有问题我非常基本的配置。我为fos_rest
配置尝试了不同的设置,但configuration reference没有提供很大帮助,因为我不太了解单个设置的功能。
我的设置:
//config.yml
sensio_framework_extra:
view:
annotations: true
fos_rest: ~
//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'
);
}
}
我的API应根据接受头返回XML奥德JSON。永远不会有html输出。
我认为,应该在官方的文档中添加(请与他们联系,并提交) 。因为它今天不存在。恭喜! –
只需提交来自日志的相关错误消息,以便人们可以通过谷歌找到这个:'PHP message:PHP致命错误:未捕获异常'RuntimeException'带消息'您需要在使用FOSRestBundle View Response侦听器时禁用SensioFrameworkExtraBundle中的视图注释“。 in /home/jupiter/symfony/dimsym/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/DependencyInjection/Compiler/ConfigurationCheckPass.php:27' –