FreeLightman
FreeLightman

Reputation: 2304

Doctrine entity with namespace within a bundle

I use symfony3. Have the only bundle - AppBundle. I use yml for annotation. They live in AppBundle\Resources\config\doctrine. If I want a new entity - I create new .orm.yml file and then run php bin/console doctrine:generate:entities AppBundle. Everything works fine.

Once I needed another namespace for my entity. So I created a folder Filter in doctrine folder. And put a Category entity there. And then called a 'generate' command. I had an error No mapping file found named 'Category.orm.yml' for class 'AppBundle\Entity\Filter\Category'. Then removed Filter folder and recall the command. And everything worked fine. So the issue is in an additional folder. I tried to place Category just in doctrine folder but keep namespace in yml file (AppBundle\Entity\Filter\Category). That does not work.

So the question is: how to create an annotation for an antity with a parent namespace?

Upvotes: 0

Views: 510

Answers (1)

baikho
baikho

Reputation: 5368

You can test it using the php bin/console doctrine:generate:entity command:

The Entity shortcut name: AppBundle:Filter/Category

This is how your project structure would be generated. No subdirectory in the doctrine directory, but instead the namespace in the YAML filename along:

src/
└── AppBundle/
    ├── Entity/
    │   ├── Filter/
    │   │   └── Category.php
    │   └── SomeEntity.php
    └── Resources/
        └── config/
            └── doctrine/
                ├── Filter.Category.orm.yml
                └── SomeEntity.orm.yml

Upvotes: 0

Related Questions