I use zend on my company but i have never started setting it up. I downloaded the framework and want to integrate doctrine... I tried to get the doctrine object using getServiceLocator() but on zend 2x it will be deprecated and when I try to do this:
public function indexAction()
{
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}
I get the following exceptions:
1 - An exception was raised while creating "Doctrine\ORM\EntityManager"; no instance returned 2 - An abstract factory could not create an instance of doctrine.entitymanager.ormdefault(alias: doctrine.entitymanager.orm_default).
So I tried to pass the doctrine object by factory... but the factory is never called. That's what I did:
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController'
),
'factories' => [
'Album\Controller\Album' => 'Album\Controller\AlbumControllerFactory'
]
),
On module.php
public function getControllerConfig()
{
return [
'factories' => [
'\Album\Controller\Album' => function() {
exit;
}
]
];
}
Nothing that I do seems to get inside the factory class.
class AlbumControllerFactory implements FactoryInterface
{
public function __construct()
{
exit;
}
public function createService(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) {
exit;
/* @var $serviceLocator \Zend\Mvc\Controller\ControllerManager */
$sm = $serviceLocator->getServiceLocator();
$em = $sm->get('Doctrine\ORM\EntityManager');
$controller = new AlbumController($em);
return $controller;
}
}
class AlbumController extends AbstractActionController
{
public function indexAction()
{
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
Here is how my structure looks like:
Thanks!