我被这个问题搞糊涂了.
我有一个带有工厂的模块表,用于我的最后一个类"Entreprise“
所以在module/Tables/config/module.config.php中
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED ... :-( ');
$entreprise = new Entreprise();
return $enteprise;
}
}module/Tables/Modules.php
<?php
namespace Tables;
class Module
{
public function getServiceConfig()
{
return [
'factories' => [
'EntrepriseTableGateway' => function ($sm)
{
...
...
$e=$sm->get(\Service\Entreprise::class);
// Here is the problem
// \Service\Entreprise is resolved
// as Tables\Service\Factory\EntrepriseFactory as expected
// but Tables\Service\Factory\EntrepriseFactory is not found...以下是工厂流程
----module/Tables/src/Tables/Service包含Entreprise.php (但此时问题不在这里)
----/module/Tables/config/module.config.php
<?php
return array(
'service_manager' => [
// the resolution works...
// but the final class is not found...
'invokables' => [
Service\Entreprise::class => \Tables\Service\Factory\EntrepriseFactory::class,
]
]
);module/Tables/src/Tables/Service/Factory.php
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED !!!');
$entreprise = new Entreprise();
return $entreprise;
}
}在composer.json中(composer转储-自动加载完成)
...
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"Tfirst\\": "module/Tfirst/src/",
"Tables\\": "module/Tables/src/"
}
},
...和在SERVER/config/modules.config.php的根配置中
...
return [
'Laminas\Db',
'Laminas\Di',
'Laminas\Mvc\Plugin\FilePrg',
'Laminas\Mvc\Plugin\FlashMessenger',
'Laminas\Mvc\Plugin\Identity',
'Laminas\Mvc\Plugin\Prg',
'Laminas\Session',
'Laminas\Mvc\I18n',
'Laminas\Mvc\Console',
'Laminas\Form',
'Laminas\Hydrator',
'Laminas\InputFilter',
'Laminas\Filter',
'Laminas\I18n',
'Laminas\Cache',
'Laminas\Router',
'Laminas\Validator',
'Application',
'Tables',
'Tfirst',
......和错误转储
Error
File:
/home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:31
Message:
Class 'Tables\Service\Factory\EntrepriseFactory' not found
Stack trace:
#0 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(765): Laminas\ServiceManager\Factory\InvokableFactory->__invoke()
#1 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(201): Laminas\ServiceManager\ServiceManager->doCreate()
#2 /home/vagrant/Code/yeting/SERVER/module/Tables/src/Module.php(246): Laminas\ServiceManager\ServiceManager->get()..。有什么建议吗?
发布于 2020-03-18 21:50:57
好的..。我发现我错了..。
实际上,我将旧的Zend2目录结构与新的Zend3教程(以及现在的Laminas)混合在一起,所以命名空间是错误的。
更正前:我的结构目录是:
(即型号:) modules/Tables/src/Tables/Model
新的结构是
(例如,对于模型:)工厂的modules/Tables/src/Model idem,等等...
总会有错误,但这是另一个问题...
我结束这个问题。
https://stackoverflow.com/questions/60721094
复制相似问题