我正在尝试使用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
文件夹中,并添加了namespace
和use 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],
];
答案 0 :(得分:1)
这可能是由于清理缓存,因为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中注册。
答案 1 :(得分:0)
在这里找到我的问题的答案:zf2 + doctrine2 and No Metadata Classes to process
我使用的教程中的示例类没有@Entity批注,因此被Doctrine跳过。