bedeabza
bedeabza

Reputation: 872

Zend Framework with modular structure + Doctrine 2

I use Zend Framework with modules for my applications and I am interested in integrating Doctrine 2 in the same fashion:

A module contains:

The problem with Doctrine 2 is that it requires to have an entity directory along with a proxy directory. I want the entities directory to be the models directory from my modular structure and based on my research I haven't found a solution.

Currently, with a default module the metadata implementation looks like this:

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

If I want to add a new module, let's say "cms" I have no way of managing the models there with Doctrine.

Is there anyone that has a solution for the problem ?

Upvotes: 6

Views: 1692

Answers (3)

Meabed
Meabed

Reputation: 3928

If you create bootstrap 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 bootsrap to load default module models

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

it will work fine

Upvotes: 0

Cobby
Cobby

Reputation: 5454

I have my proxies (auto-generated) in an application level folder, here's my directory structure:

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

Upvotes: 0

bedeabza
bedeabza

Reputation: 872

After some hours of work I came up with the correct solution. To be noted that the newDefaultAnnotationDriver, setProxyDir and setProxyNamespace methods of Doctrine's \ORM\Configuration class can receive also array parameters.

This being said, you need to pass arrays with model paths for every module and it will work

Upvotes: 4

Related Questions