In my Symfony2 project I have one bundle called MyBundle\\BlogBundle. I'm using the command:
php app/console doctrine:mapping:import MyBundleBlogBundle xml
To generate mapping files in xml format. The default location in which the mapping files are generated is:
src/MyBundle/BlogBundle/Resources/config/doctrine
I would like to change that. It would be very nice if that directory could be:
src/MyBundle/BlogBundle/Mapping
Is this even possible to do? Above all I would like to change my Entity directory to:
src/MyBundle/BlogBundle/Model
This also does not seems to work with the doctrine:mapping:import command. For this to change I tried stuff like changing the config.yml to:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
MyBundle:
mappings:
MyBundleBlogBundle:
mapping: true
type: xml
dir: Model
alias: 'MyBundleBlogBundle'
prefix: 'MyBundle\BlogBundle\Model'
is_bundle: true
But this also does not seems to work. After this I did some research on Compiler Passes as used by eg the FosUserBundle. But I don't understand a lot of that yet.
Can I get the doctrine:mapping:import command to work with my desired directories? Or do I need to forget this command and create all the mappings and entities myself?
I would prefer to solve it with a Compiler Pass, but do not know how. Most important is the use of the Model directory instead of the Entity dir.
Here is a working example. In my case, is_bundle is set to false but it should work pretty much the same. As @user3749178 has suggested, your dir is probably wrong. Tweak the locations as necessary.
doctrine:
entity_managers:
games:
connection: games
mappings:
foo1:
prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo1
type: yml
dir: "%kernel.root_dir%/../src/ProjectGameBundle/Doctrine/EntityMapping/Foo1"
is_bundle: false
foo2:
prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo2
type: yml
dir: "%kernel.root_dir%/../src/ProjectGameBundle/Doctrine/EntityMapping/Foo2"
is_bundle: false
Update
Looks like I misunderstood the main point of the question. Take a look at:
vendor/doctrine/doctrine-bundle/
namespace Doctrine\Bundle\DoctrineBundle\Command
class ImportMappingDoctrineCommand extends DoctrineCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
$destPath = $bundle->getPath();
$type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
if ('annotation' === $type) {
$destPath .= '/Entity';
} else {
$destPath .= '/Resources/config/doctrine';
}
As you can see, the mapping file directory is hard coded. No way to adjust where the xml files will end up. You will have to copy them over yourself and then edit the entity path. It's a one shot deal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.