【问题标题】:ReflectionException : Class Admin\AdminBundle\Admin\Entity\Produit does not existReflectionException:类 Admin\AdminBundle\Admin\Entity\Produit 不存在
【发布时间】:2018-06-07 12:44:39
【问题描述】:

我使用 symfony 3 并尝试管理一个管理端来管理我的产品和我的电子商务网站的命令,但我总是遇到同样的错误:

ReflectionException - 类 Admin\AdminBundle\Admin\Entity\Product 不存在

这是我的服务:

services:
app.admin.produit:
    class: Admin\AdminBundle\Admin\ProduitAdmin
    tags:
        - { name: sonata.admin, manager_type: orm, group: "Content", label: "Produit" }
    arguments:
        - ~
        - Admin\AdminBundle\Admin\Entity\Produit
        - ~
    calls:
        - [ setTranslationDomain, [AdminAdminBundle]]
    public: true


app.admin.commande:
    class: Admin\AdminBundle\Admin\CommandeAdmin
    tags:
        - { name: sonata.admin, manager_type: orm, group: "Content", label: "Commande" }
    arguments:
        - ~
        - Admin\AdminBundle\Admin\Entity\Commande
        - ~
    calls:
        - [ setTranslationDomain, [AdminAdminBundle]]
    public: true

这是我的 CommandAdmin:

    <?php
    namespace Admin\AdminBundle\Admin;



    use Sonata\AdminBundle\Admin\AbstractAdmin;
       use Sonata\AdminBundle\Show\ShowMapper;
       use Sonata\AdminBundle\Form\FormMapper;
       use Sonata\AdminBundle\Datagrid\ListMapper;
       use Sonata\AdminBundle\Datagrid\DatagridMapper;

class CommandeAdmin extends AbstractAdmin
{
    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('idProduit', 'entity', array('class' => 'Admin\AdminBundle\Entity\Produit'))
            ->add('date')
       ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
       $datagridMapper
            // ->add('idProduit')
            ->add('date')
       ;
    }

    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('idProduit', 'entity', array('class' => 'Admin\AdminBundle\Entity\Produit'))
            ->add('date')
       ;
    }

    // Fields to be shown on show action
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
           ->add('idProduit')
           ->add('date')
       ;
    }
}

这是我的产品管理员:

<?php
namespace Admin\AdminBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;

class ProduitAdmin extends AbstractAdmin
{
    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('nom')
            ->add('description')
            ->add('quantite')
            ->add('prix')
            ->add('marque')
            ->add('fournisseur')
       ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
       $datagridMapper
            ->add('nom')
            ->add('description')
            ->add('quantite')
            ->add('prix')
            ->add('marque')
            ->add('fournisseur')
       ;
    }

    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('nom')
            ->add('description')
            ->add('quantite')
            ->add('prix')
            ->add('marque')
            ->add('fournisseur')
       ;
    }

    // Fields to be shown on show action
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
           ->add('nom')
           ->add('description')
           ->add('quantite')
           ->add('prix')
           ->add('marque')
           ->add('fournisseur')
       ;
    }
}

这是堆栈跟踪:

ReflectionException:
Class Admin\AdminBundle\Admin\Entity\Produit does not exist

  at vendor/sonata-project/admin-bundle/Controller/CRUDController.php:480
  at ReflectionClass->__construct('Admin\\AdminBundle\\Admin\\Entity\\Produit')
     (vendor/sonata-project/admin-bundle/Controller/CRUDController.php:480)
  at Sonata\AdminBundle\Controller\CRUDController->createAction()
  at call_user_func_array(array(object(CRUDController), 'createAction'), array())
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:153)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:169)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web/app_dev.php:29)

如果有人有想法

【问题讨论】:

  • 你检查Admin\AdminBundle\Admin\Entity\Product是否存在?

标签: php symfony sonata


【解决方案1】:

这个错误很容易解释:Admin\AdminBundle\Admin\Entity\Produit 类似乎不存在。看看你的代码,我猜它不存在。

我最好的猜测是您的意思是Admin\AdminBundle\Entity\Produit(注意删除的Admin\ 子命名空间)。这同样适用于它下面的 Commande 类规范。

【讨论】:

  • 是的,谢谢你,你说得对。我的问题已解决。谢谢
猜你喜欢
  • 2019-11-03
  • 2016-10-02
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 2022-06-23
  • 1970-01-01
  • 1970-01-01
  • 2013-07-23
相关资源
最近更新 更多