Search code examples
routessymfony1

symfony1 route with negative number or string as id and sfDoctrineRouteCollection


I'm using symfony 1.4, i have a route like this:

user_orders:
  class: sfDoctrineRouteCollection
  options:
    model:                UserOrders
    module:               user_orders
    prefix_path:          /orders
    column:               id
    with_wildcard_routes: true
    requirements: 
      id: \w+

i would like to have orders with negative numbers in the ID field, so, when trying to access a url like this /orders/12/edit i go to the edit form page, this is ok, but, when accessing an url like /orders/-1/edit i get the error Action "orders/1" does not exist., so, i start to try with a string in the id, but when accessing url /orders/id1/edit same error appear Action "orders/id1" does not exist., so, the questions is,
is this possible or not? i mean, have a negative number by id or string in the url? the requirements in the routing config is ok or not?

best regards


Solution

  • I'm gonna answer my own question, maybe it can help someone else, the fix was simple after a few try, i need to create another route, under the user_orders route definition, to override the user_orders_edit and user_orders_update routes, finally, it looks like this:

    user_orders:
      class: sfDoctrineRouteCollection
      options:
        model:                UserOrders
        module:               user_orders
        prefix_path:          /orders
        column:               id
        with_wildcard_routes: true
      requirements: {id: \w+}
    user_orders_edit:
      url:     /orders/:id/edit.:sf_format
      class:   sfDoctrineRoute
      options: { model: UserOrders, type: object }
      param:   { module: user_orders, action: edit, sf_format: html }
      requirements: { sf_method: get, id: \w+ }
    user_orders_update:
      url:     /orders/:id.:sf_format
      class:   sfDoctrineRoute
      options: { model: UserOrders, type: object }
      param:   { module: user_orders, action: update, sf_format: html }
      requirements: { sf_method: put, id: \w+ }
    

    i couldn't use a negative number in the url, but i was able to use a string like /orders/id123/edit

    done it