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 –