Routing id为负数或字符串且SFDOCTRINEROUTECOLECTION为的symfony1路由
我使用的是symfony 1.4,我的路线如下:Routing id为负数或字符串且SFDOCTRINEROUTECOLECTION为的symfony1路由,routing,symfony1,Routing,Symfony1,我使用的是symfony 1.4,我的路线如下: user_orders: class: sfDoctrineRouteCollection options: model: UserOrders module: user_orders prefix_path: /orders column: id with_wildcard_routes: tr
user_orders:
class: sfDoctrineRouteCollection
options:
model: UserOrders
module: user_orders
prefix_path: /orders
column: id
with_wildcard_routes: true
requirements:
id: \w+
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+ }
我希望在ID字段中有负数的订单,因此,当尝试访问类似于/orders/12/edit
的url时,我转到编辑表单页面,这是可以的,但是,当访问类似于/orders/-1/edit
的url时,我得到的错误是操作“orders/1”不存在。
,因此,我开始尝试使用ID中的字符串,但是当访问url时,会出现相同的错误。操作“orders/id1”不存在。
,因此,问题是,这可能吗?我的意思是,url中的id或字符串是否有负数? 路由配置中的要求是否正常
致以最诚挚的问候我将回答我自己的问题,也许它可以帮助其他人,经过几次尝试后修复非常简单,我需要在
用户订单
路由定义下创建另一条路由,以覆盖用户订单
编辑和用户订单
更新路由,最后,它看起来是这样的:
user_orders:
class: sfDoctrineRouteCollection
options:
model: UserOrders
module: user_orders
prefix_path: /orders
column: id
with_wildcard_routes: true
requirements:
id: \w+
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+ }
我不能在url中使用负数,但我可以使用类似/orders/id123/edit
想重新提一个老问题,但我自己却偶然发现了这个问题:
要求
不是选项
的子项,而是同级(与选项级别相同)。因此,这将起作用:
user_orders:
class: sfDoctrineRouteCollection
options:
model: UserOrders
module: user_orders
prefix_path: /orders
column: id
with_wildcard_routes: true
requirements: {id: \w+}