我使用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')
;
}
}
这是我的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')
;
}
}
这是堆栈跟踪:
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\Produit
似乎不存在。看看你的代码,我猜它不存在。
我最好的猜测是你的意思是Admin\AdminBundle\Entity\Produit
(注意删除的Admin\
子名称空间)。这同样适用于您下面的Commande
类规范。