Symfony 将文档名称空间从Bundle/document更改为Bundle/Model
我使用的是DoctrineMongoDBBundle,通常我会将文档放入Symfony 将文档名称空间从Bundle/document更改为Bundle/Model,symfony,doctrine,doctrine-odm,Symfony,Doctrine,Doctrine Odm,我使用的是DoctrineMongoDBBundle,通常我会将文档放入MyBundle/Document目录,工作正常,但我希望更改为MyBundle/Model 将文档移动到新名称空间后,我收到一条错误消息 [Exception] You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles... 目前我正在使用注释来设置配置,我不想使用xml或yml。这是当前配置,我如何实现 # ap
MyBundle/Document
目录,工作正常,但我希望更改为MyBundle/Model
将文档移动到新名称空间后,我收到一条错误消息
[Exception]
You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles...
目前我正在使用注释来设置配置,我不想使用xml或yml。这是当前配置,我如何实现
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: "%database_name%"
document_managers:
default:
auto_mapping: true
假设您的文档是
Acme/Model/Invoice
可以按如下方式调整映射:
doctrine:
odm:
# ...
mappings:
Acme:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: MyDocuments
$documentManager->getRepository('MyDocuments:Invoice');
现在使用以下映射:
doctrine:
odm:
# ...
mappings:
Acme:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: MyDocuments
$documentManager->getRepository('MyDocuments:Invoice');
如果要将文档保存在捆绑包中
。。。只需使用捆绑包的名称,即AcmeDemoBundle
而不是Acme
作为映射名称,将is_bundle
设置为true
,并且dir
选项将被视为相对于捆绑包的根目录
有关映射选项的更多信息,请参见文档章节
有关如何以捆绑方式存储文档的更多信息,请参见
顺便说一句,程序与上述相同。