我的系统具有全局动态路由,允许使用相同的代码样式开发模块。
我想为这个/checkout/list/cart-type/2
生成url的痕迹,但导航配置无法匹配我的网址。
另一方面,当我只是路由到/checkout/list
时,它可以正常工作。
请帮我正确配置我的配置。
我的路由器配置
'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' => [],
],
],
],
],
],
我的导航配置
'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
],
],
],
],
],
],
答案 0 :(得分:0)
您将controller
和action
定义为参数,因此请尝试(未测试):
'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
],
],
],
],
],
],
或者:
$url('default/wildcard', [
'controller' => 'checkout',
'action' => 'list',
'cart-type' => 2
];
答案 1 :(得分:0)
我找到了解决方案。
问题在' id'子段重定义通配符路由的段路由
'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' => [],
],
],
],
]
]