Symfony 4 + Sonata Admin - 在继承 属性 中找不到 属性 的元数据
Symfony 4 + Sonata Admin - No metadata found for property in inherited property
当我尝试向管理员添加过滤器时出现错误已有一段时间了。
有两个实体:Client 和 Order.
在 OrderAdmin
文件中,以下过滤器有效:
$datagridMapper
->add('id')
->add('client.email')
->add('client.id')
;
但是如果我添加这一行 ->add('client.name')
它会触发这个错误:
No metadata found for property `App\Entity\Order::$client.name.
Please make sure your Doctrine mapping is properly configured.
Client 实体由另外两个实体继承。它们都包含 属性 名称。
而 id 和 email 都存在于父实体中。我猜这就是出现错误的原因:
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"user_1" = "one", "user_2" = "two"})
这在以前的版本上运行良好。
知道如何解决这个问题吗? (将名字 属性 转移到父 class 对我来说并不是真正的解决方案)。
编辑:订单 class
<?php
namespace App\Entity;
/**
* Order
*
* @ORM\Table(name="Order")
* @ORM\Entity(repositoryClass="App\Repository\OrderRepository")
*/
class Order
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var float
*
* @ORM\Column(name="amount", type="float", nullable=true)
*/
private $amount;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
*
* @ORM\Column(name="state", type="string", length=30, nullable=true)
*/
private $state;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Client")
*/
private $client;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="order", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $articles;
bundles.php
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => 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],
Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true],
Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
];
在这种情况下,这是由于 class 配置造成的。在 Sf DI 期间注入映射,但未找到此自定义用户 Class。
只需检查 News Bundle 使用的 classes。
sonata_news:
class:
post: Application\Sonata\NewsBundle\Entity\Post
comment: Application\Sonata\NewsBundle\Entity\Comment
media: Application\Sonata\MediaBundle\Entity\Media
user: My\Custom\UserBundle\Entity\User
通过执行此处提到的过滤器回调来解决:
https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#callback-filter
我很想知道版本之间发生了什么变化,代码不再工作,但也许在其他时间!
当我尝试向管理员添加过滤器时出现错误已有一段时间了。 有两个实体:Client 和 Order.
在 OrderAdmin
文件中,以下过滤器有效:
$datagridMapper
->add('id')
->add('client.email')
->add('client.id')
;
但是如果我添加这一行 ->add('client.name')
它会触发这个错误:
No metadata found for property `App\Entity\Order::$client.name. Please make sure your Doctrine mapping is properly configured.
Client 实体由另外两个实体继承。它们都包含 属性 名称。 而 id 和 email 都存在于父实体中。我猜这就是出现错误的原因:
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"user_1" = "one", "user_2" = "two"})
这在以前的版本上运行良好。 知道如何解决这个问题吗? (将名字 属性 转移到父 class 对我来说并不是真正的解决方案)。
编辑:订单 class
<?php
namespace App\Entity;
/**
* Order
*
* @ORM\Table(name="Order")
* @ORM\Entity(repositoryClass="App\Repository\OrderRepository")
*/
class Order
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var float
*
* @ORM\Column(name="amount", type="float", nullable=true)
*/
private $amount;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
*
* @ORM\Column(name="state", type="string", length=30, nullable=true)
*/
private $state;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Client")
*/
private $client;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="order", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $articles;
bundles.php
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => 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],
Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true],
Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
];
在这种情况下,这是由于 class 配置造成的。在 Sf DI 期间注入映射,但未找到此自定义用户 Class。
只需检查 News Bundle 使用的 classes。
sonata_news:
class:
post: Application\Sonata\NewsBundle\Entity\Post
comment: Application\Sonata\NewsBundle\Entity\Comment
media: Application\Sonata\MediaBundle\Entity\Media
user: My\Custom\UserBundle\Entity\User
通过执行此处提到的过滤器回调来解决: https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#callback-filter
我很想知道版本之间发生了什么变化,代码不再工作,但也许在其他时间!