Zend框架路由器404错误

时间:2016-09-26 16:39:44

标签: php zend-framework

这是我的zend框架模块配置:

 'routes' => [

            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],

            'default' => array(
                'type' => 'segment',
                'options' => array(
                    'route'    => '/[:controller[/:action]]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                    'constraints' => [
                        'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ]
                ),
            )
...  
 'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],

我的IndexController.php如下所示:

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }

    public function testAction()
    {
        echo 1;
        return 1;
    }
}

我希望在访问http://host/Index/test时得到正确的答案,但现在我得到404 error和类似的描述:

  

"请求的控制器无法映射到现有的控制器类......"。

问题是什么?

1 个答案:

答案 0 :(得分:0)

尝试将'type' => 'segment'更改为'type' => 'Segment'