Php 使用YAML在Symfony4中映射实体
想知道使用YAML在另一个目录中映射实体的最佳方法是什么。我有一个树结构,如下所示:Php 使用YAML在Symfony4中映射实体,php,symfony,doctrine,yaml,Php,Symfony,Doctrine,Yaml,想知道使用YAML在另一个目录中映射实体的最佳方法是什么。我有一个树结构,如下所示: | src |----User |--------Domain |------------Entity |----------------User.php |--------Infrastructure |------------Resources |----------------config |--------------------doctrine |-------------------------Us
| src
|----User
|--------Domain
|------------Entity
|----------------User.php
|--------Infrastructure
|------------Resources
|----------------config
|--------------------doctrine
|-------------------------User.orm.yml
我的条令配置文件,如下所示:
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
User:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/src/User/Infrastructure/Resources/config/doctrine'
prefix: 'App\User\Domain\Entity'
alias: User
以及User.orm.yml
映射文件:
App\User\Domain\Entity\User:
type: entity
table: users
repositoryClass: App\User\Infrastructure\Persistance\Doctrine\DoctrineUserRepository
id:
id:
type: integer
generator:
strategy: AUTO
fields:
password:
type: string
length: 64
nullable: false
email:
type: string
length: 255
unique: true
nullable: false
当我试图通过键入:bin/console原则:schema:update--force迁移模式时。
引出了以下信息:
[OK] No Metadata Classes to process.
我做错了吗
谢谢 自动映射:由于您手动提供映射信息,因此启动时为false。不确定这是否能解决问题。别名应该是App,但这不是问题的原因。是否清除了缓存rm-rf var/cache/*
?始终首先调用doc:sch:val
以验证架构<代码>文档:地图:信息
也有帮助。在这里,您的唯一
索引位于varchar(255)
和utf8mb4
(电子邮件属性)。顺便说一下,切换到xml
。phpStorm会特别喜欢这样,因为它会在您编写它时验证语法。我做了一个快速测试,您发布的信息无论自动映射的值是多少都有效。“bin/console原则:映射:info”可能是最简单的测试方法。我所能建议的就是你对拼写进行三次检查。我可以补充一点,条令实体不是域实体。您的目录结构可能不会像您希望的那样干净。@Cerad在测试中映射文件是否使用了.yml
扩展名?@gp\u是的。事实上,它需要yml。条令不承认映射文件的yaml。可能是因为yaml映射在D3中消失了。单引号没有坏处。