反射异常:Class Admin\AdminBundle\Admin\Entity\Produit 不存在

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

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

ReflectionException - Class 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)

如果有人有想法

错误很容易解释:class Admin\AdminBundle\Admin\Entity\Produit 似乎不存在。看看你的代码,我想它不在那里。

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