【发布时间】: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 文件夹并添加了 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],
];
【问题讨论】:
-
当这些链接最终失效时,您的问题和答案将变得毫无用处。准确地提出你的问题。
-
您尝试清除缓存了吗?
-
@Imanali Mamadiev 是的,我做到了。
标签: symfony doctrine-orm sonata-admin sonata symfony-sonata