我昨天才开始做Zend Framework 3教程
但是,在这一步:
当我在modules.config.php中有模块‘相册’时,我有以下错误:
Zend\ServiceManager\Exception\ServiceNotFoundException
/var/www/api/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:133
A plugin by the name "getServiceLocator" was not found in the plugin manager Zend\Mvc\Controller\PluginManager
#0 /var/www/api/vendor/zendframework/zend-mvc/src/Controller/PluginManager.php(98): Zend\ServiceManager\AbstractPluginManager->get('getServiceLocat...', NULL)
#1 /var/www/api/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(258): Zend\Mvc\Controller\PluginManager->get('getServiceLocat...', NULL)
#2 /var/www/api/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(273): Zend\Mvc\Controller\AbstractController->plugin('getServiceLocat...')
#3 /var/www/api/module/Album/src/Album/Controller/AlbumController.php(104): Zend\Mvc\Controller\AbstractController->__call('getServiceLocat...', Array)
#4 /var/www/api/module/Album/src/Album/Controller/AlbumController.php(104): Album\Controller\AlbumController->getServiceLocator()
#5 /var/www/api/module/Album/src/Album/Controller/AlbumController.php(16): Album\Controller\AlbumController->getAlbumTable()
#6 /var/www/api/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(78): Album\Controller\AlbumController->indexAction()
#7 /var/www/api/vendor/zendframework/zend-eventmanager/src/EventManager.php(271): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#8 /var/www/api/vendor/zendframework/zend-eventmanager/src/EventManager.php(151): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#9 /var/www/api/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(105): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#10 /var/www/api/vendor/zendframework/zend-mvc/src/DispatchListener.php(119): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#11 /var/www/api/vendor/zendframework/zend-eventmanager/src/EventManager.php(271): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#12 /var/www/api/vendor/zendframework/zend-eventmanager/src/EventManager.php(151): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 /var/www/api/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#14 /var/www/api/public/index.php(48): Zend\Mvc\Application->run()
#15 {main}有人能帮我吗,我真的不明白,我只是跟着课文走。谢谢!
namespace Album;
use Zend\Router\Http\Segment;
return [
'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];发布于 2017-07-25 17:42:32
在您的AlbumController类中,您调用了getServiceLocator(),但是您不应该这样做。您确定您正在遵循官方的ZF3教程吗?本教程中没有getServiceLocator()调用。您不应该必须从控制器中检索services,因为您应该在控制器中注入必要的服务(这是ZF3的方法)。
我强烈建议您从代码中删除本教程中没有的所有内容。一旦您完成了它(包括深度教程),您就会明白为什么不需要从控制器中调用一些getServiceLocator()方法.
发布于 2018-02-21 15:40:21
'view_manager‘=> [ //设置视图'display_not_found_reason’=> true,//它控制是否显示有关页面未找到错误的详细信息。'display_exceptions‘=> true,//定义是否显示有关未处理异常及其堆栈跟踪的信息。
//*** the two parameters shown above MUST be set to FALSE in production systems, because you don't want the site visitors see the details about errors in you site.
////However, you will still be able to retrieve the detailed information from Apache's error.log file
'doctype' => 'HTML5',
'not_found_template' => 'error/404', //defines the TEMPLATE NAME for the 404 error(it will be searched on template_map)
'exception_template' => 'error/index', //defines the TEMPLATE NAME for the unhandled exception error
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/default.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],正如您在上面的行中所看到的,您的代码有一些错误。嵌套作为密钥,您在属于'view_manager‘键的“template_path_stack”键中的路径。试着改变你的代码,祝你好运。
https://stackoverflow.com/questions/39639858
复制相似问题