【问题标题】:Zend Framework 2 RouterZend Framework 2 路由器
【发布时间】:2014-04-25 20:20:00
【问题描述】:

我是 ZF2 的乞讨者。我尝试做一个路由器,当我在 View 中使用时。我有这个错误: 致命错误:未捕获的异常 'Zend\Mvc\Router\Exception\RuntimeException' 带有消息 'Route with name "documents" not found'

你能帮帮我吗?

这是我的代码:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Documents\Controller\Documents' => 'Documents\Controller\DocumentsController',

        ),
    ),
    'router' => array(
        'routes' => array(
            'documents' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/DocumentsController[/:action]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',

                    ),
                    'defaults' => array(
                                                    '__NAMESPACE__' => 'Documents\Controller',
                        'controller' => 'Documents\Controller\DocumentsController',
                        'action' => 'add',
                    ),
                )
            )

            )
         )
);

谢谢

【问题讨论】:

  • 您能否编辑您的问题以将您正在使用的代码包含在生成此错误的视图中?

标签: zend-framework2 router


【解决方案1】:

您定义的“路线”名称是“文档”

尝试更改以下行

'route' => '/DocumentsController[/:action]',

'route' => '/documents[/:action]', 


同样在视图文件中,将 url 创建为 - 例如:

<?php echo $this->url('documents', array('action' => 'index')); ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-09
    • 2014-05-02
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多