【发布时间】:2013-02-24 10:38:12
【问题描述】:
我正在尝试在 symfony2 中为以下模式设置一些路由:
www.myaweseomesite.com/payment/customer/{customernumber}/{invoicenumber}
这两个参数都是可选的 - 所以以下场景必须有效:
www.myaweseomesite.com/payment/customer/{customerNumber}/{invoiceNumber}
www.myaweseomesite.com/payment/customer/{customerNumber}
www.myaweseomesite.com/payment/customer/{invoiceNumber}
我根据symfony2 doc设置了我的routing.yml。
payment_route:
pattern: /payment/customer/{customerNumber}/{invoiceNumber}
defaults: { _controller: PaymentBundle:Index:payment, customerNumber: null, invoiceNumber: null }
requirements:
_method: GET
到目前为止效果很好。问题是,如果两个参数都丢失或为空,则路由不应该工作。所以
www.myaweseomesite.com/payment/customer/
应该不起作用。有什么办法可以用 Symfony2 做到这一点?
【问题讨论】:
-
参数看起来如何?它们有长度特异性还是只有数字?只是字母?字母和数字?因为如果它们都是只有数字的任意长度,这是不可能的,因为你不知道哪个是哪个。
-
customerNumber 为数字,invoiceNumber 为字符串