ZF2 cannot match dynamic wildcard route for breadcrumb

My system has global dynamic routes which allow to develop modules using the same code style. I want to generate breadcrumb for url like this /checkout/list/cart-type/2 but navigation config cannot match my url.

On the other hand, when I simply route to /checkout/list it works correctly.

Please, help me to configure my config properly.

My router config

'router' => [
    'routes' => [
        'default' => [
            'type' => 'Segment',
            'options' => [
                'route' => '/[:controller[/[:action]]]', // global route
                'constraints' => [
                    'controller' => '[a-zA-Z]?[a-zA-Z0-9_-]*',
                    'action' => '[a-zA-Z]?[a-zA-Z0-9_-]*',
                ],
                'defaults' => [
                    'controller' => 'index',
                    'action' => 'index',
                ],
            ],
            'may_terminate' => true,
            'child_routes' => [
                'wildcard' => [
                    'type' => 'Wildcard',
                    'priority' => 10,
                    'options' => [],
                ],
            ],
        ],
    ],
],

My navigation config

'navigation' => [
    'default' => [
        'checkout' => [
            'module' => 'checkout',
            'label' => 'Home',
            'route' => 'default',
            'controller' => 'index',
            'action' => 'index',
            'pages' => [
                'checkout-list' => [
                    'label' => 'Invoices',
                    'route' => 'default/wildcard',
                    'controller' => 'checkout',
                    'action' => 'list',
                    'params' => [
                        'cart-type' => 2
                    ],
                ],
            ],
        ],
    ],
],  

Answers


You defined controller and action as parameters, so try (not tested):

'navigation' => [
    'default' => [
        'checkout' => [
            'module' => 'checkout',
            'label' => 'Home',
            'route' => 'default',
            'controller' => 'index',
            'action' => 'index',
            'pages' => [
                'checkout-list' => [
                    'label' => 'Invoices',
                    'route' => 'default/wildcard',
                    'params' => [
                        'controller' => 'checkout',
                        'action' => 'list',
                        'cart-type' => 2
                    ],
                ],
            ],
        ],
    ],
],

Or:

$url('default/wildcard', [
    'controller' => 'checkout',
    'action' => 'list',
    'cart-type' => 2
];

I found out the solution.

Problem was in 'id' child Segment route which re defined wildcard route

'default' => [
    'type' => 'Segment',
    'options' => [
        'route' => '/[:controller[/[:action]]]', // global route
        'constraints' => [
            'controller' => '[a-zA-Z]?[a-zA-Z0-9_-]*',
            'action' => '[a-zA-Z]?[a-zA-Z0-9_-]*',
        ],
        'defaults' => [
            'controller' => 'index',
            'action' => 'index',
        ],
    ],
    'may_terminate' => true,
    'child_routes' => [
        'id' => [
            'type' => 'Segment',
            'priority' => 100,
            'options' => [
                //'route' => '[/:id]', // this was changed without brackets (!)
                'route' => '/:id',
                'constraints' => [
                    'id' => '[0-9]+',
                ],
                'defaults' => [
                    'id' => '0',
                ],
            ],
            'may_terminate' => true,
            'child_routes' => [
                'wildcard' => [
                    'type' => 'Wildcard',
                    'options' => [],
                ],
            ],
        ],
    ]
]

Need Your Help

How can i use if-else condition inside for loop?

java

How can i use if-else condition inside for loop?if condition run five times and else condition run only one time not five time.