-
Notifications
You must be signed in to change notification settings - Fork 8
optional parameters #4
Comments
mmmm i am wondering if it's the $spec in ZendRouter injectRoute() method, where a child route is appended with the httpMethod....every route has a couple (or 1 at least) of autogenerated child_routes and that would cause the previous parts to be mandatory.... |
I can confirm what i suspected: kind regards |
what about creating an extra root-level route for http method negotiation instead of a child route? (... deleted example code block for modified injectRoute as we cannot put method constraints on routes of type segment ...) |
@pine3ree Try it. IIRC, we settled on the current approach as it was the only one we could find that would work while using the zend-mvc router HTTP method capabilities. Putting it at the root caused issues in that if the method was unsupported, it wouldn't even attempt to match the child routes, which would leave us with a 404 instead of a 405. We could potentially implement the method whitelisting manually inside the zend-expressive-zendrouter implementation instead, and that may be the only way we can accomplish the behavior you're wanting. |
@weierophinney right, and also zend-mvc router will still require child_(method)_routes with emtpy path to force constraints on http methods...so my requirements is indeed incompatible with its current implementation. This is actually not a bug/issue, just a missing feature of zend-mvc (as you correctly pointed out in a previous discussion it's zend-mvc related). I believe i never encounter that before with zf2 because most of the time i allowed all http methods and used controller action to distinguish between POST/GET (most of the time with form-submission and PRG). kind regards and thanks for your time.... and congrats for rc6, the expressive project is getting better and better every day. |
Hello @weierophinney.
I am still not %100 sure this is the right place for this issue.
As You suggested in : zendframework/zend-expressive#186 (comment) i tried the same route configuration with zend-mvc 2.5.x and 2.6 and it works with both versions.
what i would like to achieve is to be able tu use the UrlHelper to generate urls without the need of specifying empty string parameters for optional (nested) route parameters, as i am able to do in zf2.
a simple test front controller script:
i tried this type of route with the standard module route configuration in full-stack zf2 without
'defaults'
option and it works.when i try to generate routes with expressive UrlHelper ( and with zend-mvc router implementation),
a
Zend\Mvc\Router\Exception\InvalidArgumentException
is thrownwith message
Missing parameter "action"
(or "id")the only way to solve this is to add:
to the route configuration of zend-expressive and use this kind of route definition:
/user[/[:action[/[:id]]]]
to avoid having generated urls with double forward slashes.
The missing parameter exception is raised when a paramater is not set and (!$isOptional || $hasChild).
But since it works with zf2, I believe that it has something to do with the route building process in the zend-router brigde ($hasChild is set to true to this kind of route segment?)
Any clues?
Thanks
The text was updated successfully, but these errors were encountered: