Php 客户服务和服务工厂未在ZF3中注册
出于某种原因,我认为我的Php 客户服务和服务工厂未在ZF3中注册,php,zend-framework2,zend-framework3,zf3,Php,Zend Framework2,Zend Framework3,Zf3,出于某种原因,我认为我的'service\u manager'配置没有被正确读取。这几乎是一个全新的框架结账。也许一天的工作 我最近又做了一次,试着比较。我不知道哪里出了错 在Controller\DbBuilderController::class=>函数(ContainerInterface$container,$requestedName)指向的匿名函数下,{行$userService=$container->get(\Application\Service\userService::cl
'service\u manager'
配置没有被正确读取。这几乎是一个全新的框架结账。也许一天的工作
我最近又做了一次,试着比较。我不知道哪里出了错
在Controller\DbBuilderController::class=>函数(ContainerInterface$container,$requestedName)指向的匿名函数下,{
行$userService=$container->get(\Application\Service\userService::class);
导致错误:无法解析服务“Application\Service\userService”到工厂;您确定在配置过程中提供了吗?
我已尝试将\Application\Service\UserService::class
更改为简短、愚蠢的文字字符串,因此我确信该服务未被注册
我不知道为什么会发生这样的事,有人接受吗
<?php
namespace Application;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\LazyControllerAbstractFactory;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
use Interop\Container\ContainerInterface;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
return [
'service_manager' => [
'factories' => [
\Application\Service\UserService::class => \Application\Service\Factory\UserServiceFactory::class
],
],
'doctrine' => [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/../src/Entity']
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
]
]
]
],
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'createUser' => [
'type' => Segment::class,
'options' => [
'route' => '/createuser/:username/:password',
'defaults' => [
'controller' => Controller\DbBuilderController::class,
'action' => 'createUser',
'username' => '',
'password' => ''
],
],
],
'importTrades' => [
'type' => Literal::class,
'options' => [
'route' => '/importTrades',
'defaults' => [
'controller' => Controller\DbBuilderController::class,
'action' => 'importTrades',
],
],
],
'createExchanges' => [
'type' => Literal::class,
'options' => [
'route' => '/createExchanges',
'defaults' => [
'controller' => Controller\DbBuilderController::class,
'action' => 'createExchanges',
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
Controller\DbBuilderController::class => function(ContainerInterface $container, $requestedName) {
$entityManager = $container->get('doctrine.entitymanager.orm_default');
$userService = $container->get(\Application\Service\UserService::class);
return new Controller\DbBuilderController($entityManager, $userService);
},
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.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',
],
],
'strategies' => array(
'ViewJsonStrategy',
),
];
查看ZF3服务管理器表明它无法加载factory类,即,
class\u存在('Application\service\factory\UserServiceFactory')
失败
使用Module.php中的getAutoloaderConfig
函数或将以下内容添加到composer.json中,确保已为应用程序
命名空间注册自动加载程序:
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/"
}
},
(显然,目录已根据需要更改)然后运行composer update
如果您使用的是
Zend\Loader\StandardAutoloader
,查看ZF3服务管理器,可能还会检查包含UserServiceFactory
的目录结构是否存在键入错误,即类存在('Application\service\factory\UserServiceFactory')
失败
使用Module.php中的getAutoloaderConfig
函数或将以下内容添加到composer.json中,确保已为应用程序
命名空间注册自动加载程序:
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/"
}
},
(显然,目录已根据需要更改)然后运行composer update
如果您使用的是
Zend\Loader\StandardAutoloader
,可能还需要检查包含UserServiceFactory
的目录结构是否存在打字错误。这似乎很好。我指的是代码。您是否尝试通过factory调用DbBuilderController类?因为您没有共享有关factory类本身的任何详细信息,所以我无法再做更多问:工厂类\Application\Service\factory\UserServiceFactory::class
引用是否正确?它可能会被错误命名,而不是在您指向的文件夹中,或者以其他方式被错误引用…如果它被错误引用,它将抛出错误。我甚至试图故意错误引用它。我将包含它。Re启动您的web服务器?Opcache可能会很痛苦。您是否使用模块设置缓存?嗯..它似乎很好。我指的是代码。您是否尝试通过factory调用DbBuilderController类?由于您没有共享有关factory类本身的任何详细信息,因此我无法再问:factory类是否\Application\Service\factory\UserServiceFactory::class代码>引用是否正确?它可能被错误命名,而不是在您指向的文件夹中,或者以其他方式被错误引用…如果它被错误引用,它将抛出错误。我甚至试图故意错误引用它。我将包含它。重新启动web服务器?Opcache可能会很麻烦。是否使用模块设置缓存?
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/"
}
},