I'm refactoring and placing my doctrine2 entites/repositories and maybe proxies into separate folders.
I have it set up to read multiple entity directories, but i'm开发者_Go百科 integrating with zend framework and my models have a _
namespace , Admin_Model_Repository_User
instead of Application\Entity\Repository\User
.
Anyone have any pointers for managing multiple paths for proxies and repositories.
I'm not sure about proxies, but you can certainly specify multiple entity and repositories locations easily.
When creating the driver, you can pass either a single path string or an array. For example for xml:
$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(array(
APPLICATION_PATH . '/modules/admin/models',
APPLICATION_PATH . '/modules/default/models'
));
Or with annotations:
$driverImpl = $config->newDefaultAnnotationDriver(array(
APPLICATION_PATH . '/modules/admin/models',
APPLICATION_PATH . '/modules/default/models'
));
This works on any mapping driver. Or you can call addPath() on the $driverImpl after it is created.
For repositories if you specify the repository class in the mapping, as long as an autoloader can access it then it will work in any location.
Hey thanks, you got me on the right track. I was using zend_auth to persist the entity through session storage, and I was calling getIdentity()->getId()
, which it didn't like. Works fine without separating the entity dirs, but its no problem atm, I just persisted the id into storage and had my class recreate the object from the id.
It seems to be working now, thanks for the help
My Solution for ZF2
in file module.doctrine_orm.local.config.php
'drivers' => array(
'Admin' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'namespace' => 'Admin\Model',
'paths' => array('module/Admin/src/Admin/Model')
),
'Accounting' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'namespace' => 'Accounting\Model',
'paths' => array('module/Accounting/src/Accounting/Model')
)
),
and
'orm_driver_chain' => array(
'parameters' => array(
'drivers' => array(
'application_annotation_driver' => $settings['drivers']['Accounting'],
'application_annotation_driver2' => $settings['drivers']['Admin']
),
'cache' => $settings['cache']
)
),
精彩评论