I have tried to set up a routing in zf2 where all post data of the route /connection/add is routing to a separate method using this yaml configurations:
router:
routes:
home:
type: literal
options:
route: '/'
defaults:
controller: Admin\Dashboard
action: index
connection:
type: literal
options:
route: '/connection'
defaults:
controller: Admin\Connection
action: list
may_terminate: true
child_routes:
add:
type: literal
options:
route: '/add'
defaults:
action: add
may_terminate: true
child_routes:
post:
type: method
options:
verb: post
defaults:
action: test
Everything in the above example works just fine, except the deepest child post that is using the type of Zend\Mvc\Router\Http\Method
When one is submitting post data to the rout /connection/add, that person will be routed to the test action.
The last child in the above routing is ignored and the add action is still invoked upon dispatching post data sent from a form.
It actually is possible, it just requires a little more explicit configuration.
The reason your example wasn't working is because the router matched your 'add' route successfully and simply returned there without looking ahead. You have to tell it that it can't terminate there by setting 'may_terminate' to false and explicitly defining all methods you want to deal with in the child_routes.
add:
type: Literal
options:
route: '/add'
defaults:
action: add
may_terminate: false
child_routes:
post:
type: method
options:
verb: post
defaults:
action: test
everythingelse:
type: method
options:
verb: 'get,head,put,delete'
defaults:
action: add
Remember, the key is to set 'may_terminate' to false so the router doesn't return a match too early.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With