php - 无法加载资源“”。确保有支持“rest”类型的加载器
问题描述
我在使用 Symfony V4.99 和fosrestbundle
.
当我跑步时,php bin/console debug:router
我得到了这个:
无法加载资源“App\Controller\ListController”。确保有一个支持“rest”类型的加载器。
这是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 中,路由存在问题,请尝试:
安装这个https://github.com/handcraftedinthealps/RestRoutingBundle
#> composer 需要 handcraftedinthealps/rest-routing-bundle
然后添加到config/bundles.php这一行:
HandcraftedInTheAlps\RestRoutingBundle\RestRoutingBundle::class => ['all' => true],
推荐阅读
- python - 使用 pyvista 和 spyder 进行交互式绘图
- java - 设计复杂的验证框架:从工厂中找到正确的验证器
- dbt - 在不编译的情况下运行 dbt
- python - 如何使用对象列表制作 igraph 对象?
- python - 意外结果sklearn StandardScaler
- xaml - 样式取决于 Xamarin 表单中的屏幕方向
- swift - let myUrl = URL(string: 快速返回 nil
- mongodb - MongoDB 复制作为 Windows 上的服务
- sql - SQL 使用模式更改字符串
- python - 如何发送对象并获取该项目在Django Rest Framework分页中存在的相应页码?