我试图建立在Symfony2的部分航线以下模式: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有没有办法做到这一点?
params是怎么样的?他们有长度特异性还是数字?只是信件?字母和数字?因为如果他们都是只有数字的任何长度,这是不可能的,因为你不知道哪个是哪个。 – 2013-03-08 20:02:33
customerNumber是一个数字,invoiceNumber是一个字符串 – marty 2013-03-08 20:04:35