My problem is the following, I am currently working with symfony 6 I want to create several controllers for my administration panel except that but route is not detected by the router or by the front (twig).
I tried cleaning cache, deleting my admin folder in controller folder, renaming but file (controller file).
I launched the command php bin/console debug:router but I do not see but route
This is a part of my controller :
#[Route('/admin/user/all/', name: 'app_admin_users', methods: ['GET'])]
#[Security("is_granted('ROLE_ADMIN')")]
public function users(): Response
{
$users = $this->userService->getAllUsers();
return $this->render('admin/users/index.html.twig', [
'users' => $users,
]);
}
This is route.yaml :
controllers:
resource: ../src/Controller/
type: annotation
kernel:
resource: ../src/Kernel.php
type: annotation
End this is my front error :
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "app_admin_users" as such route does not exist.").
My Answer:
php
// src/Controller/AdminController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AdminController extends AbstractController
{
/**
* @Route("/admin", name="admin_index")
*/
public function index(): Response
{
return $this->render('admin/index.html.twig');
}
}
Make sure that you have imported the `Route` annotation correctly at the top of your controller file. Also, check if your `index.html.twig` file exists in the `templates/admin` directory.
If the route is still not being detected, try running `php bin/console cache:clear` to clear the cache completely. If the issue persists, there may be a problem with your routing configuration in `config/routes.yaml` or `config/routes/annotations.yaml`.
You can also try running `php bin/console debug:router` with the `-v` flag for more verbose output to see if the route is being registered correctly.
Rate this post
4 of 5 based on 4447 votesComments