Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 路线中的Symfony2区域设置_Php_Routes_Translation_Locale_Symfony - Fatal编程技术网

Php 路线中的Symfony2区域设置

Php 路线中的Symfony2区域设置,php,routes,translation,locale,symfony,Php,Routes,Translation,Locale,Symfony,我遵循Symfony2文档,并将区域设置添加到我的路线中。但是,当我将{{path('myroute')}}放在细枝模板中时,我找不到通过路由传递语言环境的方法,但是语言环境总是得到回退值,而不是使用当前语言环境 我尝试了{{path('myroute',{u locale':{u locale}}}}},但出现了错误“Variable”\u locale“不存在” 有什么想法吗?修复了{{path('address',{'u locale':app.request.attributes.get

我遵循Symfony2文档,并将区域设置添加到我的路线中。但是,当我将{{path('myroute')}}放在细枝模板中时,我找不到通过路由传递语言环境的方法,但是语言环境总是得到回退值,而不是使用当前语言环境

我尝试了{{path('myroute',{u locale':{u locale}}}}},但出现了错误“Variable”\u locale“不存在”

有什么想法吗?

修复了
{{path('address',{'u locale':app.request.attributes.get('u locale')}}}
多亏了这个线程

两页:

localhost.lo/xx/about

localhost.lo/xx/hello/{name}

其中xx-routing.yml中描述的几个地区

home:
  resource: "@JetInformBundle/Resources/config/routing.yml"
  prefix: /{_locale}
  requirements:
    _locale: ^en|de|ru|uk|pl$
hello:
  pattern:  /hello/{name}
  defaults: { _controller: JetInformBundle:Default:index, name: 'alexander' }

about:
  pattern:  /about
  defaults: { _controller: JetInformBundle:Default:about }
--路由.yml

home:
  resource: "@JetInformBundle/Resources/config/routing.yml"
  prefix: /{_locale}
  requirements:
    _locale: ^en|de|ru|uk|pl$
hello:
  pattern:  /hello/{name}
  defaults: { _controller: JetInformBundle:Default:index, name: 'alexander' }

about:
  pattern:  /about
  defaults: { _controller: JetInformBundle:Default:about }
--JetInformBundle routing.yml

home:
  resource: "@JetInformBundle/Resources/config/routing.yml"
  prefix: /{_locale}
  requirements:
    _locale: ^en|de|ru|uk|pl$
hello:
  pattern:  /hello/{name}
  defaults: { _controller: JetInformBundle:Default:index, name: 'alexander' }

about:
  pattern:  /about
  defaults: { _controller: JetInformBundle:Default:about }
--DefaultController.php

<?php

namespace Jet\InformBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction($name, Request $request)
    {
        return $this->render('JetInformBundle:Default:index.html.twig',
                             array('name' => $name, 'matches' =>     $this->matchAction($request)));
    }

    public function aboutAction(Request $request)
    {
        return $this->render('JetInformBundle:Default:about.html.twig',
                              array('matches' => $this->matchAction($request)));
    }

    protected function matchAction(Request $request)
    {
        return $this->get('router')->match($request->getRequestUri());
    }
}
速记法:

{{ path('address', {'_locale': app.session.locale}) }}

在Symfony2.1中,区域设置存储在请求中,因此您必须使用:

{{ path('address', {'_locale': app.request.locale}) }}

请看,这些要求不适用于导入的路线(资源)。。。所以请注意,对于这些路线,本地可以是任何东西!如何获取_locale“default”?{u locale':默认值{u locale}?因为在我的路由参数中英语是这样设置的:前缀:/{{u locale}默认值:{u locale:en@Zagloo恐怕我不明白你的问题。请考虑更好地解释它,或者打开一个新的问题,详细描述你的问题。