Php Zf2致命错误:类';BookList\Controller\BookController';找不到

Php Zf2致命错误:类';BookList\Controller\BookController';找不到,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,我正在zf2中开发一个应用程序。当我在module.config.php中定义路由并在浏览器中访问它们时,php抛出错误: 致命错误:在第170行的C:\Program Files(x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\autoclick\skeleton application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPlu

我正在zf2中开发一个应用程序。当我在
module.config.php
中定义路由并在浏览器中访问它们时,php抛出错误:

致命错误:在第170行的C:\Program Files(x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\autoclick\skeleton application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php中找不到类'BookList\src\BookList\Controller\BookController\BookController'。

这是我的module.config.php:

return array(
    'controllers' => array(
        'invokables' => array(
            'BookList\src\BookList\Controller\Book' => 'BookList\src\BookList\Controller\BookController'
        )
    ),
    'router' => array(
        'routes' => array(
            'book' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/book[/][:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+'
                    ),
                    'defaults' => array(
                        'controller' => 'BookList\src\BookList\Controller\Book',
                        'action' => 'index'
                    )
                )
            )
        )
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'book' => __DIR__ . '/../view'
        )
    )

我的
BookController
namespace
BookList\src\BookList\Controller
您不应该指定路径,而应该只指定类名,例如remove\BookList\src\part。命名空间也不应包含src文件夹。您不应指定路径,而应仅指定类名,例如remove\BookList\src\part。命名空间也不应包含src文件夹。您不应指定路径,而应仅指定类名,例如remove\BookList\src\part。命名空间也不应包含src文件夹。您不应指定路径,而应仅指定类名,例如remove\BookList\src\part。名称空间也不应包含src文件夹,这应该是:

'controllers' => array(
    'invokables' => array(
        'BookList\Controller\Book' => 'BookList\Controller\BookController' // <- change key and value
    )
),
'router' => array(
    'routes' => array(
        'book' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/book[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+'
                ),
                'defaults' => array(
                    'controller' => 'BookList\Controller\Book', // <- change
                    'action' => 'index'
                )
            )
        )
    )
),
“控制器”=>阵列(
'invokables'=>数组(
'BookList\Controller\Book'=>'BookList\Controller\BookController'//数组(
“路由”=>数组(
'book'=>数组(
'类型'=>'段',
“选项”=>数组(
'路由'=>'/book[/][:操作][/:id]',
'约束'=>数组(
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id'=>”[0-9]+'
),
“默认值”=>数组(
'controller'=>'BookList\controller\Book',//'index'
)
)
)
)
),
这应该是:

'controllers' => array(
    'invokables' => array(
        'BookList\Controller\Book' => 'BookList\Controller\BookController' // <- change key and value
    )
),
'router' => array(
    'routes' => array(
        'book' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/book[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+'
                ),
                'defaults' => array(
                    'controller' => 'BookList\Controller\Book', // <- change
                    'action' => 'index'
                )
            )
        )
    )
),
“控制器”=>阵列(
'invokables'=>数组(
'BookList\Controller\Book'=>'BookList\Controller\BookController'//数组(
“路由”=>数组(
'book'=>数组(
'类型'=>'段',
“选项”=>数组(
'路由'=>'/book[/][:操作][/:id]',
'约束'=>数组(
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id'=>”[0-9]+'
),
“默认值”=>数组(
'controller'=>'BookList\controller\Book',//'index'
)
)
)
)
),
这应该是:

'controllers' => array(
    'invokables' => array(
        'BookList\Controller\Book' => 'BookList\Controller\BookController' // <- change key and value
    )
),
'router' => array(
    'routes' => array(
        'book' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/book[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+'
                ),
                'defaults' => array(
                    'controller' => 'BookList\Controller\Book', // <- change
                    'action' => 'index'
                )
            )
        )
    )
),
“控制器”=>阵列(
'invokables'=>数组(
'BookList\Controller\Book'=>'BookList\Controller\BookController'//数组(
“路由”=>数组(
'book'=>数组(
'类型'=>'段',
“选项”=>数组(
'路由'=>'/book[/][:操作][/:id]',
'约束'=>数组(
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id'=>”[0-9]+'
),
“默认值”=>数组(
'controller'=>'BookList\controller\Book',//'index'
)
)
)
)
),
这应该是:

'controllers' => array(
    'invokables' => array(
        'BookList\Controller\Book' => 'BookList\Controller\BookController' // <- change key and value
    )
),
'router' => array(
    'routes' => array(
        'book' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/book[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+'
                ),
                'defaults' => array(
                    'controller' => 'BookList\Controller\Book', // <- change
                    'action' => 'index'
                )
            )
        )
    )
),
“控制器”=>阵列(
'invokables'=>数组(
'BookList\Controller\Book'=>'BookList\Controller\BookController'//数组(
“路由”=>数组(
'book'=>数组(
'类型'=>'段',
“选项”=>数组(
'路由'=>'/book[/][:操作][/:id]',
'约束'=>数组(
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id'=>”[0-9]+'
),
“默认值”=>数组(
'controller'=>'BookList\controller\Book',//'index'
)
)
)
)
),


你能发布一段代码吗,我不完整。请看@Tim Fountain answer你能发布一段代码吗,我不完整。请看@Tim Fountain answer你能发布一段代码吗,我不完整。请看@Tim Fountain answer你能发布一段代码吗,我不完整。请看@Tim Fountain answerI tried它和我为我的控制器类将名称空间更改为BookList\Controller,但它不起作用。您现在遇到了什么错误?您的book Controller的完整路径是什么?我的完整类路径是skeleton application\module\BookList\src\BookList\Controller\BookController,错误是致命错误:类“BookList\Controller\BookController”不是C:\Program Files(x86)中的nd\EasyPHP-DevServer-14.1VC9\data\localweb\projects\autoclick\skeleton application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php在第170行您在问题中还说您的控制器的名称空间为
BookList\src\BookList\controller
,但这应该是
BookList\controller
它仍然不起作用,请编辑您的问题以包括控制器类的前几行(最多包括
类BookController
行)。我尝试了它,并将我的控制器类的命名空间更改为BookList\Controller,但它不起作用。您现在遇到了什么错误?您的book Controller的完整路径是什么?我的完整类路径是skeleton application\module\BookList\src\BookList\Controller\BookController,错误是致命错误:类“BookList\Controller\BookController”在C:\Program文件(x86)中找不到\EasyPHP-DevServer-14.1VC9\data\localweb\projects\autoclick\skeleton application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php在第170行您在问题中还说您的控制器的名称空间为
BookList\src\BookList\controller
,但这应该是
BookList\controller
它仍然不起作用,请编辑您的问题以包括控制器类的前几行(最多和包括