2012-06-22 32 views
0

我正在使用symfony 1.0,併爲以下幾個網址設置路由。如何在symfony中爲多個參數設置路由?

static_pages: 
url: docs/:page.htm 
param: { module: docs, action: index } 

現在,我已經爲不同類型的URL設置了路由。

URL is http://news4u.com/search/description/id/3/css/a/act/a 

我已經設置路由如下

description: 
url: /search/description/id/:id/css/:manu/act/:mgh 
param: { module: search, action: description} 

是獲得「CSS」和「行爲」的值,這是正確的格式。在時刻當URL缺少的CSS參數,我的意思是如果URL是如下:

http://news4u.com/search/description/id/3/css//act/a 

的值 - getRequestParameter(「CSS」)是表示爲「行爲」和 的值 - getRequestParameter('動作')爲空

所以,我試圖應用路由選擇,並請糾正我,如果我錯了。我不希望使用上面的路由配置。

+0

這也與鏈接有關http://stackoverflow.com/questions/11034591/how-to-get-an-empty-parameter-from-an-url-像-例如-COM-ID –

回答

0

您不一定需要在routing.yml文件中指定「id」,「css」和「act」作爲參數,除非您在URL中使用它們來將用戶發送到搜索模塊和描述行動。

使用你的routing.yml下面的規則仍然會工作:

default: 
    url: /:module/:action/* 

那麼你應該能夠使用

url_for('search/description', array(
    'id' => 4, 
    'css' => 'something', 
    'act' => 'blah' 
); 

產生這樣的鏈接:/搜索/說明書/ id/4/css/something/act/blah