Php 无法加载资源“&引用;。确保有一个装载机支持;“休息”;类型

Php 无法加载资源“&引用;。确保有一个装载机支持;“休息”;类型,php,api,symfony,symfony4,fosrestbundle,Php,Api,Symfony,Symfony4,Fosrestbundle,在使用symfonyv4.99和fosrestbundle创建RESTAPI时,我遇到了这个错误 当我运行php bin/console debug:router时,我得到以下结果: 无法加载资源“App\Controller\ListController”。确保 有一个加载程序支持“rest”类型 以下是Routes.yaml的代码: lists: type : rest resource : App\Controller\ListController pr

在使用symfonyv4.99和
fosrestbundle
创建RESTAPI时,我遇到了这个错误

当我运行
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()
    {

    }
}

最新版本的FosRestBundle(3.0.2)存在错误

使用此cmd安装:composer Required friendsofsymfony/rest bundle:2.5.0

对于最新版本(>3.0),必须将路由类型从rest更改为annotation

在symfony 5.*与FOSRestBundle相比,路由存在问题,请尝试:

  • 安装这个

    #>编写器需要手工制作的LPS/rest路由包

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

    手工制作的alps\RestRoutingBundle\RestRoutingBundle::class=>['all'=>true]


  • 我假设,在你的routes.yaml中,类型可能最终是
    注释
    (完全不清楚,因为你还没有定义任何路由),如中所建议的,请分享更多详细信息-没有SymfonyI的v4.99编辑了我的帖子并添加了fos_rest.yaml的代码。