Unable to create zf2 DoctrineORMModule objects from mapping files

I have zf2 DoctrineORMModule and DoctrienModule installed. I am trying to use a command-line tool to create mapping files and generate entities from these mapping files. (I know this is not the most preferred method, but that’s how I am going to do it. I have reasons.)

I have a custom module configured, and here is my Doctrine configuration for this module.

// Doctrine config 'doctrine' => array( 'driver' => array( 'Restful_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/Restful/Entities') ), 'orm_default' => array( 'drivers' => array( 'Restful\Entities' => 'Restful_driver' ) ) ) ) 

First i run

 doctrine orm:convert-mapping xml /to/my/dest/path --from-database --force 

This will create my XML file with all the table information. This part works fine, and I can view the xml she created. Then i try to run

 doctrine orm:generate-entities /to/my/dest/path --generate-annotations --generate-methods 

I have no errors, but I am not getting any results either. The output from the previous command.

 No Metadata Classes to process. 

I tried to read, but did not find articles that really solve my problem. Most say that my annotations / mappings are not configured correctly. But I can reset the entity manager through the controller.

 var_dump($this->getServiceLocator()->get('doctrine.entitymanager.orm_default')); 

What do I need to do to get this to generate entities from xml mappings? Any help is appreciated.

+4
source share
3 answers

I had a similar problem with YAML files and brought my solution here . I am sure that this will work with xml files too. Just try adding

 $driverImpl = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array("YOUR_PATH_TO_XML_FILES")); /* @var $em \Doctrine\ORM\EntityManager */ $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default'); $em->getConfiguration()->setMetadataDriverImpl($driverImpl); 

to doctrine-module.php.

+5
source

Have you tried using the doctrine module script in vendor / bin? It should already be configured to read your application configurations.

 ./doctrine-module orm:generate-entities ~/doctrine-entities 
0
source

This error occurred because you are using the annotation driver to generate. This driver uses your existing entities and does not look at xml. If you want to create Entities from XML, you must send the DI to the configuration section of the XML section of the configuration configuration with the desired path.

I am using another module of the zf2 doctrine, and my DI configuration has a different format, so I can not send you a DI example.

0
source

Source: https://habr.com/ru/post/1445533/


All Articles