V
V
Vladimir2018-11-22 01:32:00
Doctrine ORM
Vladimir, 2018-11-22 01:32:00

How to connect doctrine to zend expressive?

I'm trying to fasten the doctrine to Zend. Here are
doctrine.global.php configs

return [
    'doctrine' => [
        'driver' => [
            'orm_default' => [
                'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class,
                'drivers' => [],
            ],
        ],
    ],
];

doctrine.local.php
return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'params' => [
                    'url' => 'mysql://project:[email protected]/project',
                ],
            ],
        ],
    ],
];

Connected inversion
return [
    'dependencies' => [
        'abstract_factories' => [
            \Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class
        ],
];

gives an error message
[email protected]:/application# php /application/vendor/doctrine/orm/bin/doctrine
PHP Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: Unable to create service "Doctrine\DBAL\Connection"; unable to resolve parameter "driver" using type hint "Doctrine\DBAL\Driver" in /application/vendor/zendframework/zend-servicemanager/src/AbstractFactory/ReflectionBasedAbstractFactory.php:226

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2018-11-23
@de1vin

everything turned out to be simple, you need to connect the ContainerInteropDoctrine factory
https://github.com/DASPRiD/container-interop-doctrine
in dependencies.global.php

'factories'  => [
            \Doctrine\ORM\EntityManager::class  => \ContainerInteropDoctrine\EntityManagerFactory::class,
        ],

N
novrm, 2018-11-22
@novrm

Something like this: https://github.com/doctrine/DoctrineORMModule#conn...

<?php
return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' => \Doctrine\DBAL\Driver\PDOMySql\Driver::class,
                'params' => [
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'username',
                    'password' => 'password',
                    'dbname'   => 'database',
                    'driverOptions' => [
                        \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
                    ],
                ],
            ],
        ],
    ],
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question