[英]Symfony 4.1 i18n route prefix: exclude route
I have a i18n project running on Symfony 4.1.我有一个在 Symfony 4.1 上运行的 i18n 项目。
I want to achieve some routing like:我想实现一些路由,如:
Following this article , I'm using annotations to handle routing and I set a global prefix to my annotations routing :在这篇文章之后,我使用注释来处理路由,并为我的注释路由设置了一个全局前缀:
site:
resource: '../src/Controller/'
type: annotation
prefix:
en: '/en'
fr: '/fr'
This way, all the routes defined in annotations from '../src/Controller/' are prefixed, which leads to a conflict between my "Choose language" page and the homepage.这样,'../src/Controller/' 的注解中定义的所有路由都带有前缀,这导致我的“选择语言”页面和主页之间发生冲突。
I want to exclude the "Choose language" page from the i18n prefixing, so I'll be able to use "/" for this page, when the homepage could stay on /fr or /en.我想从 i18n 前缀中排除“选择语言”页面,因此当主页可以保留在 /fr 或 /en 上时,我将能够为此页面使用“/”。
Any ideas to achieve this?有什么想法可以实现这一目标吗?
Defining this route at top of annotations.yaml
without prefix option:在没有前缀选项的
annotations.yaml
顶部定义此路由:
_choose_language:
path: /
controller: App\Controller\ChooseLanguageController
site:
resource: '../src/Controller/'
type: annotation
prefix:
en: '/en'
fr: '/fr'
and don't use route annotation for this special controller:并且不要为此特殊控制器使用路由注释:
class ChooseLanguageController
{
public function __invoke()
{
return new Response('Choose Language!');
}
}
then this action is being excluded from i18n prefixing.那么此操作将从 i18n 前缀中排除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.