Zend Framework 3教程错误

时间:2016-09-22 13:02:01

标签: zend-framework3

我昨天刚刚开始Zend Framework 3 tutorial

但是,at this step

当我在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',
        ],
    ],
];

2 个答案:

答案 0 :(得分:0)

AlbumController课程中,您拨打getServiceLocator(),但不一定要这样做。您确定要遵循官方的ZF3教程吗?本教程中没有getServiceLocator()调用。您不必从控制器中检索Service Manager,因为您应该在控制器中注入必要的服务(它是ZF3的方法)。

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

答案 1 :(得分:0)

'view_manager'=> [//设置视图         'display_not_found_reason'=> true,//它控制是否显示有关Page not Found错误的详细信息。         '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',
    ],
],

正如您在上面的行中所看到的,您的代码存在一些错误。您在“template_path_stack”键中嵌入了Route作为键,该键属于“ view_manager ”键。尝试更改代码并祝你好运。