无法加载资源“”确保有支持“休息”类型的装载机

问题描述

在使用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 存在问题,请尝试:

  1. 安装这个https://github.com/handcraftedinthealps/RestRoutingBundle

    #> composer require handcraftedinthealps/rest-routing-bundle

  2. 然后添加到 config/bundles.php 这一行:

    HandcraftedInTheAlps\RestRoutingBundle\RestRoutingBundle::class => ['all' => true],

,

最新版本的FosRestBundle(3.0.2)中存在错误/错误。 使用此cmd进行安装:作曲家需要friendsofsymfony / rest-bundle:2.5.0

,

对于最新的(> 3.0),必须将路由类型从“静止”更改为“注释”。 Information Here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...