0

I am new into Zend Framework 3 programming.

Previously we create a project having all database table's mapping included in one particulare module.

Now, we need to create another module into the same project. So we would like to put outside from the first module the database mapping objects in order to shared tha classes between the both modules.

I try to create a new module only for the mapping, but without succes. The namespaces doesn't existes.

After I look for solution like using ServiceManager, but I didn't really understand how to used it.

Do you know if there is another solution than using a ServiceManager ? And if not, have I change all my previous code using objects included simply with the key word use, in order to use the ServiceManager ?

Thanks.

Vicking
  • 553
  • 6
  • 15

1 Answers1

0

Finaly in my solution I create a module containing only the sources files for the doctrine mapping under src directory.

/module
  /MyApplication
    /src
      /config
         /module.config.php
  /Common
    /src
      /DoctrinMapping
         /Entities
composer.json

In composer.json I put :

"autoload": {
    "psr-4": {
         "MyApplication\\": "module/MyApplication/src/"
        ,"Common\\":"module/Common/src/"
    }
}

At the project root I execute the commande line :

composer dump-autoload

After into module.config.php of the my specifique application I define the doctrine reference as :

,'doctrine' =>
[
    'driver' =>
    [
        'common_entities' =>
        [
             'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
            ,'cache' => 'array'
            ,'paths' => array(__DIR__ . '/../../Common/src/DoctrineMapping/Entities')
        ],
        'orm_default' =>
        [
            'drivers' =>
            [
                'Common\DoctrineMapping\Entities' => 'common_entities'
            ]
        ]
    ]
]

That works, but I don't know if this is the best solution to apply.

Vicking
  • 553
  • 6
  • 15