Integrating doctrine, factory

For programming and general questions on Zend Framework
Post Reply
fern3379
Posts: 2
Joined: Tue Nov 22, 2016 4:30 pm

Integrating doctrine, factory

Post by fern3379 » Tue Nov 22, 2016 4:41 pm

Hi guys,

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:

Code: Select all

public function indexAction()
    {
        $em = $this->getServiceLocator()
            ->get('Doctrine\ORM\EntityManager');
     }
I get the following exceptions:

Code: Select all

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:

on module.config.php

Code: Select all

 '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.

Code: Select all

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:

snag. gy /tF93uB.jpg

Thanks!

stij2324
Posts: 55
Joined: Fri Nov 06, 2015 11:42 pm

Re: Integrating doctrine, factory

Post by stij2324 » Mon Dec 05, 2016 12:07 pm

Wich version of the framework are you sing zf2 or zf3?

fern3379
Posts: 2
Joined: Tue Nov 22, 2016 4:30 pm

Re: Integrating doctrine, factory

Post by fern3379 » Fri Dec 09, 2016 2:25 pm

ZF2.. But I figured it out already! Thanks!

Post Reply