zendframework / zend-router

Standalone routing implementation for HTTP and console requests
BSD 3-Clause "New" or "Revised" License
32 stars 20 forks source link

wrong dispatch #28

Closed comeUpWithItLater closed 6 years ago

comeUpWithItLater commented 7 years ago
// ./module/Editor/config/module.config.php
return [
 'router' => [
        'routes' => [
            'editor' => [
                'type'    => 'Segment',
                'options' => [
                    // Change this to something specific to your module
                    'route'    => '/editor[/:action][/][:id]',      // <-  notice it's 'editor'  here 
                    'defaults' => [
                        'controller'    => Controller\EditorController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
]
// ./module/Editorvote/config/module.config.php

return [
  'router' => [
        'routes' => [
            'editorvote' => [
                'type'    => 'Segment',
                'options' => [
                    // Change this to something specific to your module
                    'route'    => '/editorvote[/:action][/][:id]',   //<- start with  editor***
                    'defaults' => [
                        'controller'    => Controller\EditorvoteController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
]

open http://localhost/editorvote with browser, the request was dispatched to editor module( $routeMatch->getMatchedRouteName() produce editor) , but if we change ./module/Editor/config/module.config.php:

return [
 'router' => [
        'routes' => [
            'editor' => [
                'type'    => 'Segment',
                'options' => [
                    // Change this to something specific to your module
                    'route'    => '/editorX[/:action][/][:id]',   //<-change 'editor'  to  'editorX'
                    'defaults' => [
                        'controller'    => Controller\EditorController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
]

open http://localhost/editorvote , the dispatch works perfectly.

php -v
PHP 7.1.5 (cli) (built: Jun  8 2017 22:55:53) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

composer.lock:

 {
            "name": "zendframework/zend-router",
            "version": "3.0.2",
            "source": {
                "type": "git",
                "url": "https://github.com/zendframework/zend-router.git",
                "reference": "03763610632a9022aff22a0e8f340852e68392a1"
            },
            "dist": {
                "type": "zip",
                "url": "https://files.phpcomposer.com/files/zendframework/zend-router/03763610632a9022aff22a0e8f340852e68392a1.zip",
                "reference": "03763610632a9022aff22a0e8f340852e68392a1",
                "shasum": ""
            }, 
Xerkus commented 6 years ago

Pretty sure you got optional segments wrong. If it is still relevant, try 'route' => '/editor[/:action[/:id]]',