Ihave a symfony app that ignore the roytes i can declare. For exemple, i have this lines of code in routes.yaml :
app_titi
path: /titi
methods: ['GET']
defaults:
_controller: 'App\Controller\TitiController::index'
I do a cache:clear and when i try to watch the result in my browser, no route found.
The controller exists and have the right name.
My context is Symfony 6.2, PHP 8.1, runing in Docker containers.
I tryed to create a new controller, i declared it in routes.yaml, same results.
I tryed to create a controller but this time using annotations, same results.
When i ask the command router:debug, symfony console returns an empty results.
Thanks for helping!
CodePudding user response:
For a better answer please provide your controller path and code example.
In Symfony 6.2, by default, you do not have to change routes.yaml since all route declared in controller are auto detected if you keep this inside routes.yaml.
Here is my routes.yaml for example :
controllers:
resource: ../src/Controller/
type: annotation
kernel:
resource: ../src/Kernel.php
type: annotation
Then inside the controller
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
// This not annotation but php attribute, i advise you to use it instead
#[Route('/', name: "home")]
public function home(): Response
{
return $this->render('website/index.html.twig');
}
}
Read this to understand why symfony now use php attribute :
https://symfony.com/blog/new-in-symfony-5-2-php-8-attributes
CodePudding user response:
@ThomasL
Hi, here is my routes.yaml :
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
app_titi:
path: /titi
methods: ['GET']
defaults:
_controller: 'App\Controller\TitiController::index'
Others routes are now declared in attributes.
This is my Titi controller :
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class TitiController extends AbstractController
{
#[Route('/titi', name: 'app_titi')]
public function index(): Response
{
return $this->render('titi/index.html.twig', [
'controller_name' => 'TitiController',
]);
}
}