-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected: 5.1.0
Description
Routes configured inside a file routes.php are not recognized, resulting in the error "No route found for "GET /something" (404 Not Found)". When running debug:router
, these routes are not listed.
The same route works great when configured in routes.yaml
.
In a different project using Symfony 5.0.8
, route configuration via routes.php
works perfectly.
I don't know if this is really a bug or a case of outdated documentation. The change was made in this commit, that makes the method configureRoutes
rely only in .yaml
files.
This following commit makes it possible to use .php
files again, but this change was reverted.
How to reproduce
- Create a controller:
<?php
//src/Controller/SchoolController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class SchoolController
{
public function list()
{
return new Response('ok');
}
}
- Create a
routes.php
file:
<?php
//config/routes.php example
use App\Controller;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return function(RoutingConfigurator $routes)
{
$routes->add('schools_list', '/schools')
->controller([Controller\SchoolController::class, 'list'])
->methods(['GET']);
};
- Running
debug:router
will result in:
---------------- -------- -------- ------ --------------------------
Name Method Scheme Host Path
---------------- -------- -------- ------ --------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
---------------- -------- -------- ------ --------------------------
- Configure the same route inside
routes.yaml
:
#config/routes.yaml
schools_list:
path: /schools
controller: App\Controller\SchoolController::list
methods: GET
- Running
debug:router
will result in:
---------------- -------- -------- ------ --------------------------
Name Method Scheme Host Path
---------------- -------- -------- ------ --------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
schools_list GET ANY ANY /schools
---------------- -------- -------- ------ --------------------------