【问题标题】:Symfony 4 + Sonata + Sonata Doctrine ORM Admin Bundle: Error: No Metadata classes to processSymfony 4 + Sonata + Sonata Doctrine ORM Admin Bundle:错误:没有要处理的元数据类
【发布时间】:2019-01-12 17:33:05
【问题描述】:

我正在尝试使用 Sonata Doctrine ORM Admin Bundle 让 Sonata 与 Symfony 4 一起工作。

我已经安装了以下(不确定是否所有这些都是必要的)并将我的数据库详细信息添加到 .env 文件中,这确实显示了一个空白的奏鸣曲管理页面。

symfony-skeleton
sonata-project/admin-bundle
sonata-project/doctrine-orm-admin-bundle
symfony/orm-pack
symfony annotations

现在我想将实体添加到我的项目中,因此我从教程中复制了一些实体,将它们放入 src\Entity 文件夹并添加了 namespaceuse as ORM 语句:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

// ...
use Doctrine\Common\Collections\ArrayCollection;
// ...

class Category
{
    // ...

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string")
     */
    private $name;

    /**
    * @ORM\OneToMany(targetEntity="BlogPost", mappedBy="category")
    */
    private $blogPosts;

    public function __construct()
    {
        $this->blogPosts = new ArrayCollection();
    }

    public function getBlogPosts()
    {
        return $this->blogPosts;
    }

    // ...
}

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

// ...
class BlogPost
{
    // ...

    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string")
     */
    private $title;

    /**
     * @var string
     *
     * @ORM\Column(name="body", type="text")
     */
    private $body;

    /**
     * @var bool
     *
     * @ORM\Column(name="draft", type="boolean")
     */
    private $draft = false;

    /**
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="blogPosts")
     */
    private $category;
}

但是当我运行php bin/console doctrine:schema:create 时,它告诉我No Metadata classes to process.

我错过了什么?

app\config\packages\doctrine.yaml:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    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:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

app\config\bundles.php:

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Sonata\DatagridBundle\SonataDatagridBundle::class => ['all' => true],
    Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
    Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
    Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
    Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
];

【问题讨论】:

  • 当这些链接最终失效时,您的问题和答案将变得毫无用处。准确地提出你的问题。
  • 您尝试清除缓存了吗?
  • @Imanali Mamadiev 是的,我做到了。

标签: symfony doctrine-orm sonata-admin sonata symfony-sonata


【解决方案1】:

在这里找到我的问题的答案:zf2 + doctrine2 and No Metadata Classes to process

我使用的教程中的示例类没有 @Entity 注释,因此被 Doctrine 跳过。

【讨论】:

  • 哇,Symfony 到底有多烂真是太疯狂了!有同样的问题:/
【解决方案2】:

这可能是由于清理了缓存,因为 Doctrine 正在缓存所有数据。试试这个命令:

php bin/console cache:clear --env=prod
php bin/console cache:clear --env=dev

您应该在 app/config/config.yml 文件中包含此配置:

doctrine:

    ...

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            AppBundle:
                mapping: true
                type: annotation
                alias: Blog
                prefix: App\Bundle\Entity

并确保您的 Sonata AdminBundle 已在 AppKernel 中注册。

【讨论】:

  • 我没有 app/config/config.xml 文件,您提到的设置似乎在我的 app/config/packages/doctrine.yaml 文件中,但看起来与您的略有不同,我会用它更新我的 OP。
猜你喜欢
  • 2017-05-18
  • 2017-01-25
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 2023-04-01
  • 2016-09-03
  • 1970-01-01
  • 2016-04-20
相关资源
最近更新 更多