Reputation: 341
Im my module.config.php file got following excerpt:
return array( 'service_manager' => array( 'aliases' => array( 'Util\Dao\Factory' => 'modelFactory', ), 'factories' => array( 'modelFactory' => function($sm) { $dbAdapter = $sm->get('Doctrine\ORM\EntityManager'); return new \Util\Dao\Factory($dbAdapter); }, ) ), 'doctrine' => array( 'driver' => array( 'application_entities' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array( __DIR__ . '/../src/Application/Model' ), ), 'orm_default' => array( 'drivers' => array( 'Application\Model' => 'application_entities' ) ), ), ),
How do i put the block "doctrine" in module class?
Upvotes: 0
Views: 61
Reputation: 16455
Well, this is actually fairly simple. Probably your Module class has the method getConfig()
. That method usually loads moduleName/config/module.config.php
.
So in whatever function you are, simply call the getConfig()
-method. This is pure and basic php ;)
//Module class
public function doSomethingAwesome() {
$moduleConfig = $this->getConfig();
$doctrineConfig = isset($moduleConfig['doctrine'])
? $moduleConfig['doctrine']
: array('doctrine-config-not-initialized');
}
However you need to notice that this only includes your Modules config. If you need to gain access to the merged configuration, you'll need to do that in the onBootstrap()
-method. Which would be done like this:
//Module class
public function onBootstrap(MvcEvent $mvcEvent)
{
$application = $mvcEvent->getApplication();
$serviceLocator = $application->getServiceLocator();
$mergedConfig = $serviceLocator->get('config');
$doctrineConfig = isset($mergedConfig['doctrine'])
? $mergedConfig['doctrine']
: array('doctrine-config-not-initialized');
}
This works similar if you're attaching to some events...
Upvotes: 0