I'm trying to get Sonata working with Symfony 4 using the Sonata Doctrine ORM Admin Bundle.
I've installed the following (not sure if all of this is necessary) and added my database details to the .env file and this does show me a blank sonata admin page.
symfony-skeleton
sonata-project/admin-bundle
sonata-project/doctrine-orm-admin-bundle
symfony/orm-pack
symfony annotations
Now I want to add entities to my project, so I've copied some entities from a tutorial, put them in the src\Entity
folder and added the namespace
and the use as ORM
statements:
<?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;
}
// ...
}
and
<?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;
}
But when I run php bin/console doctrine:schema:create
it tells me No Metadata classes to process.
What am I missing?
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
and 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],
];
Found the answer to my question here: zf2 + doctrine2 and No Metadata Classes to process
The example classes from the tutorial I was using didn't have the @Entity annotation and were therefore skipped by Doctrine.