Проблема с параметром сегмента маршрута Zend Framework 3 - PullRequest
0 голосов
/ 13 октября 2019

В моем module.config.php у меня есть конфигурация маршрута, как показано ниже. На маршруте " hizmetgetir " у меня есть параметр с именем " search " и ограничения для него. Но у меня есть такая ошибка: «Запрошенный URL не может быть сопоставлен путем маршрутизации».

Когда я меняю ограничения « search » с « id »У меня нет проблем, и я могу поймать параметр поиска маршрута в моем контроллере. по моему мнению, имя параметра и имя ограничения должны совпадать. В чем проблема. Спасибо.

Старый

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

My All Route conf.

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