0
votes

how to add parameters in the url_for() function? I mean, I have this route:

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

I want to generate the url through url_for('category_set_representative_image', $category), but how to add besides the parameter ":id" (the id of the image that will be representative of the category)?

sf 1.4

Javi

3

3 Answers

1
votes

the url_for('category_set_representative_image', $category) works indeed if you have only one parameter. If you want to add more parameters, you can use url_for('category_set_representative_image', array('sf_subject' => $category, 'extra_param' => 'foo')).

So the sf_subject is the object that is used for the object routing. All other params will be tried to be matched in the URL itself, and if not found appended as a query string.

(For example, of you have a route with url /categories/:id/params/:extra_param, it will fill the :extra_param token, and your URL will look like /categories/11/params/foo, if it isn't defined in the routing, the url will look like /categories/:id?extra_param=foo. In both cases you can get the value of the parameter in the action with $request->getParameter().

0
votes

Use this:

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

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

for routes you will have to use the @ in front