如何解决无法加载资源“”确保有支持“休息”类型的装载机
在使用Symfony V4.99和fosrestbundle
创建REST API时遇到此错误。
当我运行php bin/console debug:router
时,我得到了:
无法加载资源“ App \ Controller \ ListController”。确保 有一个支持“休息”类型的装载机。
这是Routes.yaml的代码:
lists:
type : rest
resource : App\Controller\ListController
prefix : api
这是fos_rest.yaml的代码:
fos_rest:
format_listener:
rules:
- { path: ^/,fallback_format: json,priorities: [ 'json' ] }
exception:
enabled: true
view:
view_response_listener: 'force'
formats:
json: true
这是ListController.php的代码:
<?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
class ListController extends AbstractFOSRestController
{
Public function getListsAction()
{
}
}
解决方法
在 symfony 5.* 与 FOSRestBundle 中, routes 存在问题,请尝试:
-
安装这个https://github.com/handcraftedinthealps/RestRoutingBundle
#> composer require handcraftedinthealps/rest-routing-bundle
-
然后添加到 config/bundles.php 这一行:
HandcraftedInTheAlps\RestRoutingBundle\RestRoutingBundle::class => ['all' => true],
最新版本的FosRestBundle(3.0.2)中存在错误/错误。 使用此cmd进行安装:作曲家需要friendsofsymfony / rest-bundle:2.5.0
,对于最新的(> 3.0),必须将路由类型从“静止”更改为“注释”。 Information Here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。