doutong7216 2017-12-26 18:51
浏览 61
已采纳

ReflectionException:类Admin \ AdminBundle \ Admin \ Entity \ Produit不存在

I use symfony 3 and I try to manage an admin side to manage my products and my commands for my ecommerce website, but I always have the same error :

ReflectionException - Class Admin\AdminBundle\Admin\Entity\Product does not exist

this is my services :

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

This is my 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')
       ;
    }
}

This is my ProduitAdmin :

<?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')
       ;
    }
}

This is the Stack Trace :

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)

If someone have an idea

  • 写回答

1条回答 默认 最新

  • duansha8115 2017-12-26 19:18
    关注

    The error is pretty explainable: The class Admin\AdminBundle\Admin\Entity\Produit doesn't seem to exists. Take a look at your code, I guess it's not there.

    My best guess would be that you mean Admin\AdminBundle\Entity\Produit (note the removed Admin\ subnamespace). The same applies to your Commande class specification just below it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看