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:
<?php
// composer require zendframework/(zend-mvc|zend-uri);
use Zend\Mvc\Router\Http\TreeRouteStack;
include dirname(__DIR__) . '/vendor/autoload.php';
$router = new TreeRouteStack();
$router->addRoute('user', [
'type' => 'segment',
'options' => [
'route' => 'user[/:action[/:id]]',
// 'defaults' => [
// 'action' => 'index',
// ]
],
]);
header('Content-Type: text/plain; charset=utf-8');
$params = [];
$uri = $router->assemble($params, [
'name' => 'user',
]);
echo 'Uri with params=' . json_encode($params) . ' = ' . $uri . "\n";
$params = [
'action' => 'read',
'id' => 123,
];
$uri = $router->assemble($params, [
'name' => 'user',
]);
echo 'Uri with params=' . json_encode($params) . ' = ' . $uri . "\n";
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 thrown
with message Missing parameter "action"
(or "id")
the only way to solve this is to add:
'options' => [
'defaults' => [
'action' => '',
'id' => '',
],
],
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