1. 在 app/conig中建立一个自命名的文件: abc.yml

2. 在 app/config/config.yml中导入abc.yml

文件头部:

imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: abc.yml }

3. 在abc.yml中定义变量:

parameters:
myname: wangyingxi

4. 在代码中便可以使用了:

某action中:

$key = $this->container->getParameter('myname');
return new Response($key);

app.php是程序入口!

$request = Request::createFromGlobals()

$request=$this->getRequest();

$host = $request->getHost();

获取传参:

GET的参数:$request->query->get('aparam')

POST的参数:$request->request->get('bar', 'default value if bar does not exist');

HttpFundation里面的内容具体查看:

http://symfony.com/doc/current/book/http_fundamentals.html

多语言版本实现思路:

1. 在Symfony的route.yml配置

gy_mall_t1:
pattern: /t1
host: www.a.com
defaults: { _controller: GyMallBundle:Default:t1, _locale: global }

gy_mall_t2:
pattern: /t1
host: www.a.cn
defaults: { _controller: GyMallBundle:Default:t1, _locale: cn }

- 分类域名

- 分别传参(locale值)

2. Action部分可以接受到参数

public function t1Action() {

  echo 'current locale is : ' . $this->get('translator')->getLocale();

  // $this->get('translator')->setLocale('fr');

  exit;

}

3. 在/web/.htaccess中添加:

RewriteCond %{HTTP_HOST} ^a\.com
RewriteRule ^(.*)$ http://www.a.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^a\.cn
RewriteRule ^(.*)$ http://www.a.cn/$1 [R=301,L]

如果修改了.htaccess却无效,可以清空浏览器cookie再试试

清空cache,重启apache2

http://segmentfault.com/q/1010000000212748

http://stackoverflow.com/questions/11412476/how-to-translate-language-in-symfony-2-according-to-accept-language-header

http://symfony.com/doc/current/book/translation.html#book-translation-locale-url

(暂无用到下面这篇文章)

http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html

最新文章

  1. High Precision Timers in iOS / OS X
  2. 创建数据库指定路径sql
  3. Python面向对象1
  4. Posix IPC
  5. WordPress Backdoor未授权访问漏洞和信息泄露漏洞
  6. Centos6.4 为用户添加sudo功能
  7. java类的初始化
  8. golang中container/heap包源码分析
  9. Sqlmap Tamper大全(1)
  10. 剑指offer数组3
  11. Python的自动补全
  12. POST 上传 JSON 数据
  13. Latex citation using natbib and footnotesize
  14. ORACLE SQL Developer日期显示格式不全
  15. Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换(转载)
  16. google-gson 使用及GsonBuilder设置
  17. tomcat源码阅读之过滤器
  18. Sqlserver查询数据库文件大小和剩余空间
  19. 几种常见的Web服务器
  20. 转载----开发运维资产管理系统cmdb一些观点扯淡

热门文章

  1. tp查询顺序
  2. 2.1Python基础语法(一)之注释与数据类型:
  3. 等我干IT发财了,就和你离婚。。。。。
  4. DOM相关方法,属性整理
  5. PAT乙级真题及训练题 1025. 反转链表 (25)
  6. 解决ThinkPHP中开启调试模式无法加载模块的问题。
  7. Spring-IOC 扩展点 BeanFactoryPostProcessor及其子接口解析
  8. Spring之 Aspect Oriented Programming with Spring
  9. JDBC中的SPI实现
  10. 利用Python爬取豆瓣电影