2010-09-14 70 views
5

我的symfony應用程序應該從子域得到用戶的語言:symfony的語言選擇基於子域

en.project.com - 英語 fr.project.com - 法國

等等... 特殊過濾器從當前uri獲取'GET'param'lang'並將其保存在用戶屬性中。 如何爲多個子域設置apache虛擬主機配置?

+0

我的咖啡應該是熱的,但相反,它是溫和的.. – 2010-09-14 09:28:05

回答

0

嘗試在你的httpd配置文件將其添加爲ServerAlias

2
<VirtualHost *:80> 
ServerName blah.com 
ServerAlias de.blah.com en.blah.com fr.blah.com 
... 
</VirtualHost> 

瞭解更多關於服務器別名:第一個請求期間http://httpd.apache.org/docs/2.0/en/mod/core.html#serveralias

你Symfony的過濾器可以直接解析域名,並設置一個會話變量。 這是未經測試,但應該工作:

<?php class localeFilter extends sfFilter 
{ 
    public function execute($filterChain) 
    { 
    // Execute this filter only once 
    if ($this->isFirstCall()) { 
     $host = $_REQUEST['HTTP_HOST']; 
     $locale = array_shift(explode(".",$host)); 
     $this->getUser()->setAttribute('locale', $locale); 
    } 

    // Execute next filter 
    $filterChain->execute(); 
    } 
} ?>