symfonysymfony4symfony-routing

Symfony routing, separate route setup and ignore _locale prefix?


I have in my annotations.yaml following setup to use annotation route setup:

controllers:
    resource: '../../src/Controller/'
    type: annotation
    prefix:
        en: ''
        sr: '/es'
        de: '/fr'
kernel:
    resource: ../../src/Kernel.php
    type: annotation

My question here is can I create a separated area like mysite.com/userarea without locale prefix?

It's protected area and I can use users language. I tried with this symfony route docs but I would like to keep annotations.

At the moment it looks like mysite.com/es/userarea but I would wish mysite.com/userarea.


Solution

  • Yes, you can create a dedicated namespace on controllers and create another annotation configuration like this :

    controllers:
        resource: ../../src/Controller/*
        exclude: ../../src/Controller/Admin
        type: annotation
    
    secure_area:
        resource: ../../src/Controller/Admin/*
        prefix: /userarea
        type: annotation