Symfony2 Sonata:自定义类中没有实体管理器 [英] Symfony2 Sonata: No Entity Manager in Custom Class
本文介绍了Symfony2 Sonata:自定义类中没有实体管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Sonata-Admin 中创建自定义表单,但我没有为类 School\ChildBirthBundle\Entity\DataChapter 定义实体管理器
I'm trying to create custom Form in Sonata-Admin and Im geting No entity manager defined for class School\ChildBirthBundle\Entity\DataChapter
我的代码:
namespace School\ChildBirthBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Knp\Menu\ItemInterface as MenuItemInterface;
use School\ChildBirthBundle\Entity\DataChapter;
class DataChapterAdmin extends Admin
{
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('name')
->add('status')
;
}
sonata.admin.data_chapter:
class: School\ChildBirthBundle\Admin\DataChapterAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Chapter" }
arguments:
- ~
- School\ChildBirthBundle\Entity\DataChapter
- ~
- @doctrine.orm.default_entity_manager
calls:
- [ setTranslationDomain, [SchoolChildBirthBundle]]
实体看起来像这样
namespace School\ChildBirthBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="data_chapter")
*/
class DataChapter
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*/
protected $name;
/**
* @ORM\Column(type="integer", length=1)
*/
protected $status;
/**
* @ORM\Column(type="integer")
*/
protected $idSubject;
}
我不知道我做错了什么
推荐答案
也许这是您的管理服务声明中的问题,如果您查看文档,则没有第四个参数:
Maybe it's an issue in your admin service declaration, if you check the documentation there is no 4th argument :
你应该有:
sonata.admin.data_chapter:
class: School\ChildBirthBundle\Admin\DataChapterAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Chapter" }
arguments:
- ~
- School\ChildBirthBundle\Entity\DataChapter
- ~
calls:
- [ setTranslationDomain, [SchoolChildBirthBundle]]
这篇关于Symfony2 Sonata:自定义类中没有实体管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文