php - Symfony 5 在某些请求中没有检测到正确的语言环境
问题描述
我正在为 Symfony 如何设置语言环境而苦苦挣扎。
这是我的annotations.yaml
文件:
controllers_frontend:
resource: ../../src/Controller/Frontend
type: annotation
host:
'de-DE': example.de
'de-AT': example.at
'de-CH': example.ch
'fr-CH': example.ch
prefix:
de-DE: '' # don't prefix URLs for German
de-AT: ''
de-CH: '/de'
fr-CH: '/fr'
这非常适用于控制器 A 中的路由“some-route”:
example.de/some-route -> locale = de-DE
example.at/some-route -> locale = de-AT
example.ch/de/some-route -> locale = de-CH
然后我有一个不同的控制器 B,在这里我有以下问题:
example.de/swatch/checkout/confirm -> locale not detected, it goes back to the fall back locale
example.at/swatch/checkout/confirm -> locale not detected, it goes back to the fall back locale
example.ch/de/swatch/checkout/confirm -> locale = de-CH
这是该路线的代码
<?php
namespace App\Controller\Frontend;
...
class OrderController extends AbstractController
{
/**
* @Route("/swatch/checkout/confirm", priority="10", name="swatch_checkout_confirm")
*/
public function checkout_confirm(Request $request, OrderHelper $orderHelper)
{
$country = $orderHelper->getCountry($request->getLocale());
return $this->render('frontend/order/checkout_confirm.html.twig',
array(
'country' => $country
)
);
}
由于我在 annotations.yaml 中的语言环境设置适用于“some-route”,我相信它是正确的。
解决方案
我找到了解决方案。当我从路由中删除“优先级”时,可以正确检测到语言环境。不确定这是 Symfony 中的错误还是我的语言环境设置错误。
推荐阅读
- c# - 如何将数据存储在基于服务的数据库中?
- swift - MacOS:tableView:viewForTableColumn:row:在一定数量的行后停止调用
- jestjs - 测试一个 promise 是否被拒绝?
- r - 嵌套logit模型顺序估计的奇点问题
- python - Selenium - linux mint 上的 executable_path 问题
- java - Java 通过 SSO 从 Rest API Jira 获取 json
- webdriver - TestCafe 的自定义 TestRail 报告器无法获取测试结果
- ffmpeg - 使用 x265 编译 FFMPEG 时出现错误:使用 pkg-config 找不到 x265
- android - 在 ubuntu 18.04 上构建 android-7.1.2_r36 失败
- php - ArticleController::update() 缺少参数 1