Zend Framework with a modular structure + Doctrine 2

I use the Zend Framework with modules for my applications, and I'm interested in integrating Doctrine 2 in the same way:

The module contains:

  • Controllers
  • Models
  • view
  • Assistants

The problem with Doctrine 2 is that this requires you to have an object directory along with a proxy directory. I want the object catalog to be the catalog of models from my modular structure and based on my research, I did not find a solution.

Currently, with the default module, the metadata implementation is as follows:

$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(APPLICATION_PATH . '/modules/default/models')); 

If I want to add a new module, say "cms", I have no way to manage the models there with Doctrine.

Does anyone have a solution to the problem?

+6
php zend-framework doctrine2
source share
3 answers

After several hours of work, I came up with the right solution. It should be noted that the methods newDefaultAnnotationDriver, setProxyDir and setProxyNamespace of the Doctrine \ ORM \ Configuration class can also receive array parameters.

In this case, you need to pass arrays with samples for each module, and it will work

+4
source share

I have my proxies (automatically generated) in the application level folder, here is my directory structure:

 /project /application /domain /proxies /configs /modules /blog /controllers /views /domain /entities /services /repositories /library /public /data 
0
source share

If you create a boot file for each module

 <?php class User_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'User_', 'basePath' => dirname(__FILE__) . '/modules/user', )); return $autoloader; } } 

and put this in the default boot boot to load the default module models

 protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Default_', 'basePath' => dirname(__FILE__) . '/modules/default', )); return $autoloader; } 

it works great

0
source share

All Articles