Closed jgauthi closed 10 months ago
@jgauthi I just checked on my project, I don't have such issue.
I checked with:
api:
resource: "@PTCApiBundle/Controller/"
type: attribute
prefix: /api
The Rest controller:
<?php
namespace PTC\ApiBundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
...
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Rest\Route('/stats')]
class StatisticController extends AbstractController
{
#[Rest\View('')]
#[Rest\Get('/registration/{id}', requirements: ['id' => '\d+'])]
public function registrationAction(?int $id = null): RegistrationTO
{
php bin/console debug:router --show-controllers ptc_api_statistic_registration
+--------------+---------------------------------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------------------------------+
| Route Name | ptc_api_statistic_registration |
| Path | /api/stats/registration/{id} |
| Path Regex | {^/api/stats/registration(?:/(?P<id>\d+))?$}sD |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | GET |
| Requirements | id: \d+ |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: PTC\ApiBundle\Controller\StatisticController::registrationAction() |
| | id: NULL |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+---------------------------------------------------------------------------------+
I checked with my controler extending AbstractController
or AbstractFOSRestController
but it's the same, it doesn't matter.
Thank for your response. After several tests, I found the solution.
The content of the file config/routes.yaml has been commented. Instead, I create a new file config/routes/controller.yaml with the same content (with additionnal ../
in path value). The api route configuration work and classic controller too.
On my current project (Symfony 6.2, FosRestBundle 3.5), I have a config file for the FosRest route:
:heavy_check_mark: Annotation version:
:x: I want to edit this file for attribute support, but it's not work :(.
The symfony config/routes.yaml use the standard code from Symfony 6, exemple.
When I check with
php bin/console debug:router
, the routes does not use the Api prefix in url:The Rest controller:
How to edit the "config/routes/fos_rest.yaml" file for support attributes and prefix ?