【发布时间】:2015-08-03 11:38:57
【问题描述】:
我遇到了以下问题。我正在开发一个项目,其中路线将取决于语言环境变量。目前正在运行,但它有一些我想解决的问题。
我得到的结构是这样的:
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;
到目前为止它可以工作,但问题是从文件中读取而不是从会话中读取。我想知道如何从会话中注入该值
【问题讨论】:
-
您的问题已在此处得到解答:[stackoverflow.com/questions/19484027/… [1]:stackoverflow.com/questions/19484027/…