0

I'm trying to create custom Form in Sonata-Admin and Im geting No entity manager defined for class School\ChildBirthBundle\Entity\DataChapter

My code:

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]]

And entity looks like this

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;
 }

I dont know what im doing wrong

3sco
  • 1
  • 1

2 Answers2

0

No entity manager defined for class School\ChildBirthBundle\Entity\DataChapter 500 Internal Server Error - RuntimeException

 in vendor/sonata-project/doctrine-orm-admin-bundle/Model/ModelManager.php at line 223  -

            $em = $this->registry->getManagerForClass($class);
            if (!$em) {
                throw new \RuntimeException(sprintf('No entity manager defined for class %s', $class));
            }
            $this->cache[$class] = $em;
3sco
  • 1
  • 1
0

Maybe it's an issue in your admin service declaration, if you check the documentation there is no 4th argument :

https://sonata-project.org/bundles/admin/master/doc/reference/getting_started.html#step-3-create-an-admin-service

You should have :

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]]
HypeR
  • 2,186
  • 16
  • 22