0
我遇到了以下问题。我正在开发一个项目,其中路线将取决于区域设置变量。目前正在工作,但它有一些我想解决的问题。在Symfony2中从路由访问语言环境变量
我得到的结构是这样的一个:
AppBundle
->config
->routing.en.yml #routes in English
->routing.es.yml #routes in Spanish
->routing.php #in charge of making the magic
#/app/config/routing.yml
app:
resource: "@AppBundle/config/routing.php"
type: php
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
#@AppBundle/config/routing.es.yml
about_us:
path: /nosotros
defaults: { _controller: AppBundle:Default:about }
#@AppBundle/config/routing.en.yml
about_us:
path: /about_us
defaults: { _controller: AppBundle:Default:about }
php文件被调用,这是它做什么
//@AppBundle/config/routing.php
<?php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Yaml\Yaml;
$collection = new RouteCollection();
$collection->addCollection(
$loader->import("@AppBundle/Controller/", "annotation")
);
$config = Yaml::parse(__DIR__."/../../../app/config/parameters.yml");
$locale = $config["parameters"]["locale"];
$routes = Yaml::parse(__DIR__."/routing.{$locale}.yml");
foreach($routes as $name => $data)
{
$collection->add($name, new Route($data["path"],$data["defaults"]));
}
return $collection;
它迄今为止的作品,但问题是,从阅读文件,而不是来自会话。我想知道我该如何注入会议的价值
您的问题已经在这里找到答案: [http://stackoverflow.com/questions/19484027/translations-in-symfony-2-3-locale-in-request][1] [1]:http://stackoverflow.com/questions/19484027/translations-in-symfony-2-3-locale-in-request –