1

我昨天才开始学习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}

谁能帮帮我,我真的不明白,我只是按照tuto。谢谢 !

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',
        ],
    ],
];
4

2 回答 2

0

在你的AlbumController课堂上,你打电话给getServiceLocator(),但你不应该这样做。你确定你在关注官方的 ZF3 教程吗?本教程中没有getServiceLocator()调用。您不必从控制器中检索服务管理器,因为您应该在控制器中注入必要的服务(这是 ZF3 的做法)。

我强烈建议您从代码中删除所有不在教程中的内容。一旦你完成它(包括深入教程),你就会明白为什么你真的不应该getServiceLocator()从你的控制器中调用一些方法......

于 2017-07-25T17:42:32.333 回答
0

'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”键中的Route。尝试更改您的代码并祝您好运。

于 2018-02-21T15:40:21.137 回答