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

时间:2013-08-30 13:13:28

标签: php zend-framework2

我在zend框架中运行两个模块。 1是管理(后端),另一个是客户端(前端)。我为这两个模块分配了两个虚拟主机。后端工作正常。而且,在前端我得到了索引页面。但是当我试图在第二页上移动时,它会给我一个错误:

A 404 error occurred

Page not found.

The requested controller could not be mapped to an existing controller class.
Controller:
Client\Controller\Search(resolves to invalid controller class or alias:       Client\Controller\Search)
No Exception available

这是我的module.config.php文件的主要部分......

'controllers'  => array(
    'invokables' => array(
        'Client\Controller\Index'          => 'Client\Controller\IndexController',
        'Client\Controller\Search'         => 'Client\Controller\SearchController',
    ),
),

在路由器中这是第二页路由的代码..

'search' => array(
            'type'    => 'segment',
            'options' => array(
                'route'       => '/search[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults'    => array(
                    'controller' => 'Client\Controller\Search',
                    'action'     => 'index',
                ),
            ),
        ),

我不知道,发生了什么。将不胜感激。

1 个答案:

答案 0 :(得分:1)

'controllers'  => array(
    // 
    'classes' => array(
        'Client\Controller\Index'          => 'Client\Controller\IndexController',
        'Client\Controller\Search'         => 'Client\Controller\SearchController',
    ),
    'invokables' => array(
        'Client\Controller\Index'          => 'Client\Controller\IndexController',
        'Client\Controller\Search'         => 'Client\Controller\SearchController',
    ),
),
'search' => array(
            'type'    => 'Segment', // <- I added S
            'options' => array(
                'route'       => '/search[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults'    => array(
                    'controller' => 'Client\Controller\Search',
                    'action'     => 'index',
                ),
            ),
        ),

如果不起作用,请告诉我们 module.php