首页 > 解决方案 > 使用 YAML 在 Symfony4 中映射实体

问题描述

想知道使用 YAML 在另一个目录中映射实体的最佳方法是什么。我有一个像下面这样的树结构:

| 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 doctrine:schema:update --force. 导致消息:

[OK] No Metadata Classes to process.

我为此做错了吗?

谢谢!

标签: phpsymfonydoctrineyaml

解决方案


推荐阅读