ZF2でdoctrine 2を使用しようとすると、次のエラーが発生します。ZF2 ServiceManagerがdoctrine.entitymanager.orm_defaultを作成できません
のZend \ ServiceManager \ ServiceManagerは:: getがフェッチまたはdoctrine.entitymanager.orm_default
必要なモジュールが含まれ、活性化するためにインスタンスを作成することができませんでした。
doctrine.config.local.php
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => [
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'password',
'dbname' => 'database',
'charset' => 'utf8',
'driverOptions' => [
1002 => 'SET NAMES utf8'
],
],
],
],
'configuration' => [
'orm_default' => [
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'generate_proxies' => false,
]
]
]
];
コアモジュールのmodule.config.php(/module/Core/config/module.config.php)
namespace Core;
return [
'service_manager' => include __DIR__ . '/service-manager.config.php',
'router' => include __DIR__ . '/router.config.php',
'view_manager' => include __DIR__ . '/view-manager.config.php',
'translator' => include __DIR__ . '/translator.config.php',
'hydrators' => include __DIR__ . '/hydrators.config.php'
];
コアモジュールのdoctrine.config.php(/module/Core/config/doctrine.config.php)
return [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => [
__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity',
]
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ => __NAMESPACE__ . '_driver'
]
]
]
];
工場
namespace Event\Form\Fieldset\Factory;
use Event\Entity\Event;
use Event\Form\Fieldset\EventFieldset;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class EventFieldsetFactory implements FactoryInterface {
public function createService(ServiceLocatorInterface $formElementManager) {
$serviceLocator = $formElementManager->getServiceLocator();
$hydratorManager = $serviceLocator->get('HydratorManager');
// Here I get the error!
$objectManager = $serviceLocator->get('Doctrine\ORM\EntityManager');
$fieldset = new EventFieldset();
$fieldset->setObjectManager($objectManager);
$fieldset->setHydrator($hydratorManager->get('Core\Hydrator\Doctrine'));
$fieldset->setObject(new Event());
return $fieldset;
}
}
モジュールapplication.config.php
'modules' => [
'DoctrineModule',
'DoctrineORMModule',
'Core',
'Event',
'Inquiry'
]
スタックトレースで
Zend\ServiceManager\Exception\ServiceNotFoundException
ファイル:
/src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:555
メッセージ:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for doctrine.entitymanager.orm_default
スタックトレース:
#0 /src/vendor/doctrine/doctrine-orm-module/src/DoctrineORMModule/Service/EntityManagerAliasCompatFactory.php(44): Zend\ServiceManager\ServiceManager->get('doctrine.entity...')
#1 [internal function]: DoctrineORMModule\Service\EntityManagerAliasCompatFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'doctrineormenti...', 'Doctrine\ORM\En...')
#2 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(934): call_user_func(Array, Object(Zend\ServiceManager\ServiceManager), 'doctrineormenti...', 'Doctrine\ORM\En...')
#3 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(1092): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Array, 'doctrineormenti...', 'Doctrine\ORM\En...')
#4 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(634): Zend\ServiceManager\ServiceManager->createFromFactory('doctrineormenti...', 'Doctrine\ORM\En...')
#5 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(597): Zend\ServiceManager\ServiceManager->doCreate('Doctrine\ORM\En...', 'doctrineormenti...')
#6 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#7 /src/module/Event/src/Event/Form/Fieldset/Factory/EventFieldsetFactory.php(22): Zend\ServiceManager\ServiceManager->get('Doctrine\ORM\En...')
#8 [internal function]: Event\Form\Fieldset\Factory\EventFieldsetFactory->createService(Object(Zend\Form\FormElementManager\FormElementManagerV2Polyfill), 'eventfieldsetev...', 'Event\Fieldset\...')
#9 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(934): call_user_func(Array, Object(Zend\Form\FormElementManager\FormElementManagerV2Polyfill), 'eventfieldsetev...', 'Event\Fieldset\...')
#10 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(330): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Array, 'eventfieldsetev...', 'Event\Fieldset\...')
#11 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(287): Zend\ServiceManager\AbstractPluginManager->createServiceViaCallback(Array, 'eventfieldsetev...', 'Event\Fieldset\...')
#12 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(634): Zend\ServiceManager\AbstractPluginManager->createFromFactory('eventfieldsetev...', 'Event\Fieldset\...')
#13 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(597): Zend\ServiceManager\ServiceManager->doCreate('Event\Fieldset\...', 'eventfieldsetev...')
#14 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#15 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(161): Zend\ServiceManager\ServiceManager->get('Event\Fieldset\...', true)
#16 /src/vendor/zendframework/zend-form/src/FormElementManager/FormElementManagerTrait.php(38): Zend\ServiceManager\AbstractPluginManager->get('Event\Fieldset\...', Array, true)
#17 /src/vendor/zendframework/zend-form/src/Factory.php(111): Zend\Form\FormElementManager\FormElementManagerV2Polyfill->get('Event\Fieldset\...')
#18 /src/vendor/zendframework/zend-form/src/Form.php(176): Zend\Form\Factory->create(Array)
#19 /src/module/Inquiry/src/Inquiry/Form/InquiryForm.php(19): Zend\Form\Form->add(Array)
#20 /src/vendor/zendframework/zend-form/src/FormElementManager/FormElementManagerV2Polyfill.php(217): Inquiry\Form\InquiryForm->init()
#21 [internal function]: Zend\Form\FormElementManager\FormElementManagerV2Polyfill->callElementInit(Object(Inquiry\Form\InquiryForm), Object(Zend\Form\FormElementManager\FormElementManagerV2Polyfill))
#22 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(664): call_user_func(Array, Object(Inquiry\Form\InquiryForm), Object(Zend\Form\FormElementManager\FormElementManagerV2Polyfill))
#23 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(597): Zend\ServiceManager\ServiceManager->doCreate('Inquiry\Form\In...', 'inquiryforminqu...')
#24 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#25 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(161): Zend\ServiceManager\ServiceManager->get('Inquiry\Form\In...', true)
#26 /src/vendor/zendframework/zend-form/src/FormElementManager/FormElementManagerTrait.php(38): Zend\ServiceManager\AbstractPluginManager->get('Inquiry\Form\In...', Array, true)
#27 /src/module/Inquiry/src/Inquiry/Controller/Factory/InquiryControllerFactory.php(23): Zend\Form\FormElementManager\FormElementManagerV2Polyfill->get('Inquiry\Form\In...')
#28 [internal function]: Inquiry\Controller\Factory\InquiryControllerFactory->createService(Object(Zend\Mvc\Controller\ControllerManager), 'inquirycontroll...', 'Inquiry\Control...')
#29 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(934): call_user_func(Array, Object(Zend\Mvc\Controller\ControllerManager), 'inquirycontroll...', 'Inquiry\Control...')
#30 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(330): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Array, 'inquirycontroll...', 'Inquiry\Control...')
#31 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(287): Zend\ServiceManager\AbstractPluginManager->createServiceViaCallback(Array, 'inquirycontroll...', 'Inquiry\Control...')
#32 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(634): Zend\ServiceManager\AbstractPluginManager->createFromFactory('inquirycontroll...', 'Inquiry\Control...')
#33 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(597): Zend\ServiceManager\ServiceManager->doCreate('Inquiry\Control...', 'inquirycontroll...')
#34 /src/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#35 /src/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(161): Zend\ServiceManager\ServiceManager->get('Inquiry\Control...', true)
#36 /src/vendor/zendframework/zend-mvc/src/DispatchListener.php(94): Zend\ServiceManager\AbstractPluginManager->get('Inquiry\Control...')
#37 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#38 /src/vendor/zendframework/zend-eventmanager/src/EventManager.php(490): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#39 /src/vendor/zendframework/zend-eventmanager/src/EventManager.php(263): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#40 /src/vendor/zendframework/zend-mvc/src/Application.php(340): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#41 /src/public/index.php(15): Zend\Mvc\Application->run()
#42 {main}
を彼らは正しい? –
これ以上の文脈がなければなぜこのエラーが発生するのかが分かりません。このエラーが発生した場所の工場コードとapplication.config.phpを表示してください。 –
はい、申し訳ありませんが、私は昨日急いでしまったので、ソースコードを追加できませんでした。今私はそれを追加しました。 –