Symfony 4+Sonata+Sonata Doctrine ORM管理捆绑包:错误:没有要处理的元数据类



我正试图使用Sonata Doctrine ORM管理包让Sonata与Symfony 4一起工作。

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

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

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

<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
// ...
use DoctrineCommonCollectionsArrayCollection;
// ...
class Category
{
// ...
/**
* @var string
*
* @ORMColumn(name="name", type="string")
*/
private $name;
/**
* @ORMOneToMany(targetEntity="BlogPost", mappedBy="category")
*/
private $blogPosts;
public function __construct()
{
$this->blogPosts = new ArrayCollection();
}
public function getBlogPosts()
{
return $this->blogPosts;
}
// ...
}

<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
// ...
class BlogPost
{
// ...
/**
* @var string
*
* @ORMColumn(name="title", type="string")
*/
private $title;
/**
* @var string
*
* @ORMColumn(name="body", type="text")
*/
private $body;
/**
* @var bool
*
* @ORMColumn(name="draft", type="boolean")
*/
private $draft = false;
/**
* @ORMManyToOne(targetEntity="Category", inversedBy="blogPosts")
*/
private $category;
}

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

我错过了什么?

appconfigpackagesdoctrine.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: 'AppEntity'
alias: App

appconfigbundles.php:

<?php
return [
SymfonyBundleFrameworkBundleFrameworkBundle::class => ['all' => true],
SymfonyBundleTwigBundleTwigBundle::class => ['all' => true],
SymfonyBundleSecurityBundleSecurityBundle::class => ['all' => true],
SonataDatagridBundleSonataDatagridBundle::class => ['all' => true],
SonataCoreBundleSonataCoreBundle::class => ['all' => true],
SonataBlockBundleSonataBlockBundle::class => ['all' => true],
KnpBundleMenuBundleKnpMenuBundle::class => ['all' => true],
SonataAdminBundleSonataAdminBundle::class => ['all' => true],
DoctrineBundleDoctrineCacheBundleDoctrineCacheBundle::class => ['all' => true],
DoctrineBundleDoctrineBundleDoctrineBundle::class => ['all' => true],
SonataDoctrineORMAdminBundleSonataDoctrineORMAdminBundle::class => ['all' => true],
DoctrineBundleMigrationsBundleDoctrineMigrationsBundle::class => ['all' => true],
SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle::class => ['all' => true],
];

在这里找到了我的问题的答案:zf2+doctrine2和无元数据类来处理

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

这可能是由于清理了缓存,因为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: AppBundleEntity

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

相关内容

  • 没有找到相关文章

最新更新