路由无法匹配请求的URL

时间:2015-05-10 17:37:13

标签: php zend-framework routing zend-framework2 url-routing

我正在尝试访问 sitename / news / id / 1,但它给了我这个错误。我一直试图在过去30分钟内修复它,我无法弄清楚我做错了什么。

配置:

            //...
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]/id/[/:id]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'id'         => '[0-9]+',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
            'news' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/news/id[/:id]',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'news',
                    ),
                ),
            ),
        ),
    ),
    //...

2 个答案:

答案 0 :(得分:1)

您的news路线属于literal类型。但它应该是Segment类型。

有关不同的路线类型,请参阅http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html#http-route-types

答案 1 :(得分:0)

我认为您希望这与您的默认设置相匹配'路线。由于该路线是您的申请路线的子路线,example.com/application/news/id/1将匹配,但不匹配example.com/news/id/1。我将摆脱应用程序路由,并在其位置只有默认路由。