1

情况就是这样。我的 config.yml 包含休闲集:

...
framework:
    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    ...

我正在尝试通过以下方式访问控制器中default_locale的值:

...
$this->container->getParameter('framework.default_locale');
...

但它不会工作......知道为什么它提示我这个值没有定义吗?

问候

4

1 回答 1

0

试试 $this->container->getParameter('locale');

语言环境必须在 parameters.yml 中定义

于 2015-05-31T05:00:44.507 回答