简体   繁体   中英

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
                    ],
                ],
            ],
        ],
    ],
],  

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' => [],
                ],
            ],
        ],
    ]
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM