2011-08-08 30 views
0

如何在url_for()函數中添加參數?我的意思是,我有這樣的路線:symfony:關於url_for的問題

category_set_representative_image: 
    url:  /categoria-settare-immaggine-rappresentativa/:id 
    param: { module: category_new, action: setRepresentativeImage } 
    class: sfPropelRoute 
    options: { model: Category, type: object } 

我想通過url_for('category_set_representative_image', $category)生成的URL,但如何除了添加參數「:身份證」(圖像,這將是代表品類的id)?

SF 1.4

哈維

回答

1

url_for('category_set_representative_image', $category)工作的確,如果你只有一個參數。如果你想添加更多的參數,你可以使用url_for('category_set_representative_image', array('sf_subject' => $category, 'extra_param' => 'foo'))。因此,sf_subject是用於對象路由的對象。所有其他參數將被嘗試在URL本身中進行匹配,並且如果未找到,則將其附加爲查詢字符串。

(例如,你有一個網址/categories/:id/params/:extra_param的路線,這將填補:extra_param令牌,你的URL看起來像/categories/11/params/foo,如果不在路由定義的URL看起來像/categories/:id?extra_param=foo。 在這兩種情況下,您都可以通過$request->getParameter()獲得參數值。

0

使用此:

url_for('category_set_representative_image?id=YOURIDHERE', $category); 
0

url_for('@category_set_representative_image?id=YOURIDHERE', $category);

你將不得不使用@在前方的路線