首页 > 解决方案 > Zend Framework 3 Route Segment 参数问题

问题描述

在我的 module.config.php 中,我有一个如下所示的路由配置。在“ hizmetgetir ”路线,我有名为“ search ”的参数,以及它的约束。但我有这样的错误:“请求的 URL 无法通过路由匹配。”。

当我用“ id ”更改约束“ search ”时,我没有问题,我可以在控制器中捕获路由搜索参数。在我看来,参数名称和约束名称必须相同。问题是什么。谢谢。

老的

'hizmetgetir' => [
    'type' => \Zend\Router\Http\Segment::class,
    'options' => [
        'route' => '/hizmetgetir[/:search]',
            'constraints' => [
            **'search' => '/[0-9a-zA-Z\s\'.;-]+/',**
        ],
        'defaults' => [
            'controller' => Controller\ProfilController::class,
            'action' => 'ajaxhizmetgetir',
        ],
    ],
]

新的

'hizmetgetir' => [
    'type' => \Zend\Router\Http\Segment::class,
    'options' => [
        'route' => '/hizmetgetir[/:search]',
            'constraints' => [
            'id' => '/[0-9a-zA-Z\s\'.;-]+/',
        ],
        'defaults' => [
            'controller' => Controller\ProfilController::class,
            'action' => 'ajaxhizmetgetir',
        ],
    ],
],

我的全路线会议。

'router' => [
    'routes' => [
        'rehberim' => [
            'type' => 'Literal',
            'options' => [
                // Change this to something specific to your module
                'route' => '/rehberim',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action' => 'index',
                ],
            ],
        ],
        'profil' => [
            'type' => \Zend\Router\Http\Literal::class,
            'options' => [
                'route' => '/profil',
                'defaults' => [
                    'controller' => Controller\ProfilController::class,
                    'action' => 'index',
                ],
            ],
            'may_terminate' => true,
            'child_routes' => [
                'hizmetgetir' => [
                    'type' => \Zend\Router\Http\Segment::class,
                    'options' => [
                        'route' => '/hizmetgetir[/:search]',
                            'constraints' => [
                            'id' => '/[0-9a-zA-Z\s\'.;-]+/',
                        ],
                        'defaults' => [
                            'controller' => Controller\ProfilController::class,
                            'action' => 'ajaxhizmetgetir',
                        ],

                    ],
                ],
                'profiluzman' => [
                    'type' => Segment::class,
                    'options' => [
                        'route' => '/profiluzman[/:id]',
                        'defaults' => [
                            'action' => 'profiluzman',
                        ],
                        'constraints' => [
                            'id' => '[0-9]+',
                        ],
                    ],
                ],
                'profiluser' => [
                    'type' => \Zend\Router\Http\Segment::class,
                    'options' => [
                        'route' => '/profiluser[/:id]',
                        'defaults' => [
                            'action' => 'profiluser',
                        ],
                        'constraints' => [
                            'id' => '[0-9]+',
                        ],
                    ],
                ],
                'profiladay' => [
                    'type' => \Zend\Router\Http\Segment::class,
                    'options' => [
                        'route' => '/profiladay[/:id]',
                        'constraints' => [
                            'id' => '[0-9]+',
                        ],
                        'defaults' => [
                            'action' => 'profiladay',
                        ],

                    ],
                ],
                'profilolustur' => [
                    'type' => \Zend\Router\Http\Segment::class,
                    'options' => [
                        'route' => '/profilolustur',
                        'defaults' => [
                            'action' => 'profilolustur',
                        ],
                    ],
                ],
            ],
        ],
    ],
]

标签: routeszend-framework3segment

解决方案


推荐阅读