我在zf2中开发应用程序。当我在module.config.php
中定义路由并在我的浏览器中访问它们时,php会抛出错误:
Fatal error: Class 'BookList\src\BookList\Controller\BookController' not found in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\autoclick\skeleton-application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 170
这是我的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
命名空间BookList\src\BookList\Controller
答案 0 :(得分:2)
这应该是:
'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'
)
)
)
)
),
答案 1 :(得分:1)
您不应指定路径,而只应指定类名,例如remove \ BookList \ src \ part。命名空间也不应该容纳src文件夹