可以是存储在其他位置的实体,而不是实体目录中的实体?

ram*_*moo 5 symfony

我试图在MyBundle/OtherNamespacePart/Entity目录中存储实体.

如果我运行doctrine:schema:create,我收到此错误消息:

类MyBundle/Entity/MyEntity不存在且无法加载.

我不明白,为什么忽略"OtherNamespacePart"(应该是MyBundle/OtherNamespacePart/Entity/MyEntity).我检查了整个项目,如果有所有命名空间和命名正确,在我看来似乎没问题.如果我直接在实体目录中存储实体,它可以工作(只需要删除所有"OtherNamespacePart").

控制台命令工具中没有问题,是否需要实体目录中的实体?有任何变通方法或配置选项吗?

小智 15

您可以通过提供自定义映射来实现此目的 config.yml

例如:

doctrine:
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: false
        mappings:
            name:
                type: xml
                dir: %kernel.root_dir%/../src/Your/Bundle/Resources/config/doctrine
                alias: MyModels
                prefix: MyBundle\OtherNamespacePart\Entity
                is_bundle: false
Run Code Online (Sandbox Code Playgroud)