0
votes

I have the following I have the following settings at routing.yml:

show_collection:
  url:   /:module/collection/:collection
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  param: { module: collection, action: showcollection }

collection:
  url:   /collection/
  param: { module: collection, action: index }

The link works correctly, however with one problem. The link is this:

frontend_dev.php/collection/showcollection/collection/{name of collection}

So it's making /module/action/module/name_of_collection. What I needed was:

 frontend_dev.php/collection/showcollection/{name of collection}

It would make a lot more sense even though it works as it is now. I already looked at jobeet and other routing tutorials, however I can't figure out what's wrong.

Thanks in advance!

EDIT:

Heres the url_for:

url_for(array(
      'module' => 'collection',
      'action' => 'showcollection',
      'collection' => $collection->getName()
))

This is the result:

  .../collection/showcollection/collection/{collection Name}
1
And how would it work if you change the show_collection url to /:module/:collection? Wouldn't fit your needs? - Dani Sancas
Well, it does the same thing. And the url is actually working in two different ways. The way I described and the way I want. However I'm not beeing able to get tue url_for or the link_to to construct the link how I want. - Pedro Tentugal
Why aren't you able to use url_for or link_to? Maybe there's the problem :( - Dani Sancas
Well, I already updated the route... I'm trying different solutions like passing the ID instead of the collection name. - Pedro Tentugal
Did you remove the generic routing rules from the file? Also have a look at @pfefferle's answer and it should work. - Michal Trojanowski

1 Answers

2
votes

Try to change the route to:

show_collection:
  url:   /:module/:action/:collection
  class:   sfDoctrineRoute
  options: { model: Category, type: object }
  param: { module: collection, action: showcollection }

and use

url_for('@show_collection?collection='.$collection->getName());