ZF3如何在首页路由中使用可选参数

时间:2019-01-31 10:13:33

标签: php zend-framework3 zend-router

我无法在本地路由中添加可选参数。

这是我当前的路由器:

'routes' => [
    'home' => [
        'type' => Segment::class,
        'options' => [
            'route' => '/[:salon/]',
            'constraints' => [
                'salon' => '[a-zA-Z][a-zA-Z0-9_-]*'
            ],
            'defaults' => [
                'controller' => 'Application\Controller\Index',
                'action'     => 'index',
                'salon'      => 'test'
            ],
        ],
    ],
    'application' => [
        'type'    => Segment::class,
        'options' => [
            'route' => '/application[/:controller[/:action]]',
            'constraints' => [
                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
            ],
            'defaults' => [
                '__NAMESPACE__' => 'Application\Controller',
                'controller' => 'Application\Controller\Index',
                'action'     => 'index',
            ],
        ],
        'may_terminate' => true,
        'child_routes' => [
            'default' => [
                'type' => 'wildcard'
            ]
        ]
    ],
],

我的控制器:

<?php

namespace Application\Controller;

class IndexController extends AbstractController
{
    public function indexAction()
    {
        var_dump($this->params('salon'));
        die;
    }
}

domain.ltd / 这有效,并且我正在获取沙龙参数的默认值“测试”

domain.ltd/test123 预期值为“ test123”,但这会向我显示404错误:路由无法匹配所请求的URL。

0 个答案:

没有答案