Reputation: 93
I face this Error while creating a REST API using Symfony V4.99 and fosrestbundle
.
When I Run php bin/console debug:router
I get this:
Cannot load resource "App\Controller\ListController". Make sure there is a loader supporting the "rest" type.
Here is the code of Routes.yaml:
lists:
type : rest
resource : App\Controller\ListController
prefix : api
Here is the code of 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
Here is the code of 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()
{
}
}
Upvotes: 3
Views: 8784
Reputation: 345
in symfony 5.* versus FOSRestBundle there is a problem with routes , try:
install this https://github.com/handcraftedinthealps/RestRoutingBundle
#> composer require handcraftedinthealps/rest-routing-bundle
then add to config/bundles.php this line :
HandcraftedInTheAlps\RestRoutingBundle\RestRoutingBundle::class => ['all' => true],
Upvotes: 1
Reputation: 176
For newest (>3.0) you must change the route type from rest to annotation. Information Here
Upvotes: 2
Reputation: 1
There is a bug/error with the recent version of FosRestBundle (3.0.2) Use this cmd to install it : composer require friendsofsymfony/rest-bundle:2.5.0
Upvotes: 0