ZF2控制器映射问题

时间:2014-08-24 01:05:38

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

我是Zend的新手。 我在zend.local设置了本地设备 我正在创建一个新模块说 Csv ,当我像zend.local / csv这样访问网址时,它会给我以下错误 enter image description here

我的module.config.php位于以下位置:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Csv\Controller\Csv' => 'Csv\Controller\IndexController',
        ),
    ),
     'router' => array(
         'routes' => array(
             'csv' => array(
                 'type'    => 'segment',
                 'options' => array(
                     'route'    => '/csv[/][:action][/:id]',
                     'constraints' => array(
                         'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                         'id'     => '[0-9]+',
                     ),
                     'defaults' => array(
                         'controller' => 'Csv\Controller\IndexController',
                         'action'     => 'index',
                     ),
                 ),
             ),
         ),
     ),

    'view_manager' => array(
        'template_path_stack' => array(
            'csv' => __DIR__ . '/../view',
        ),
    ),
);

2 个答案:

答案 0 :(得分:1)

您提供了错误的控制器名称:

             'defaults' => array(
                 'controller' => 'Csv\Controller\IndexController',
                 'action'     => 'index',
             ),

应该是

             'defaults' => array(
                 'controller' => 'Csv\Controller\Csv',
                 'action'     => 'index',
             ),

根据你的配置

'controllers' => array(
    'invokables' => array(
        'Csv\Controller\Csv' => 'Csv\Controller\IndexController',
    ),
),

答案 1 :(得分:-1)

您需要may_terminate选项以确保路由器可以将csv视为终止的路由。

'csv' => array(
    'type'    => 'segment',
    'options' => array(
        'route'    => '/csv[/][:action][/:id]',
        'constraints' => array(
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'     => '[0-9]+',
        ),
        'defaults' => array(
            'controller' => 'Csv\Controller\IndexController',
            'action'     => 'index',
        ),
    ),
    'may_terminate' => true // added
),
相关问题