儿童路线不起作用

时间:2017-03-23 10:26:56

标签: php zend-framework routing zend-route zend-framework3

我是Zend-Framework3的新手。

将我的ZF2应用程序迁移到ZF3。

在这个孩子路线不起作用。

这是来自<a href="#princip-detail" class="showDetail">Continue</a> <script> $(document).ready(function() { $('.showDetail').click(function() { $('#princip-detail').fadeIn(); if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); }); </script>

的路由器
module.config.php

当我尝试致电'router' => [ 'routes' => [ 'application' => [ 'type' => Segment::class, 'options' => [ 'route' => '/application', 'defaults' => [ 'controller' => Controller\IndexController::class, 'action' => 'index', ], ], 'may_terminate' => true, 'child_routes' => [ 'kk' => [ 'type' => Literal::class, 'options' => [ 'route' => 'kk', 'defaults' => [ 'controller' => Controller\IndexController::class, 'action' => 'kk' ], ], ], ] ] ], ], 时。它会生成/application/kk

我哪里错了?或者我是否必须手动注册所有操作?

1 个答案:

答案 0 :(得分:3)

  

...我是否必须手动注册所有操作?

不,您在路线值

中缺少/个字符
'router' => [
    'routes' => [
        'application' => [
            'type' => Segment::class,
            'options' => [
                'route' => '/application',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action' => 'index',
                ],
            ],
            'may_terminate' => true,
            'child_routes' => [
                'kk' => [
                    'type' => Literal::class,
                    'options' => [
                        'route' => '/kk', <-- here
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action' => 'kk'
                        ],
                    ],
                ],
            ]
        ]
    ],
],

只要存在操作kk,就不会出现404错误。

如果您的路线与动作名称相同。您可以使用Segment类型:

    'application' => [
        'type'    => Segment::class,
        'options' => [
            'route'    => '/application[/:action]',
            'constraints' => [
                'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
            ],
            'defaults' => [
                'controller' => Controller\IndexController::class,
                'action'     => 'index',
            ],
        ],
    ]