No Entity Manager in Custom Class and ContextErrorException

后端 未结 1 435
慢半拍i
慢半拍i 2021-01-21 08:33

I\'m trying to create custom Form in Sonata-Admin and I want to get data from database to choices box. When I\'m trying to get data via getEntityManager() I got error

1条回答
  •  迷失自我
    2021-01-21 08:55

    You get error because add manager in wrong place. First argument of admin service should be set as the admin service’s code (defaults to the service’s name).

    Admin class pharse this string and build some logic based on. You put there manager so you get error.

    If you want to add something to your admin class you can simply add as fourth argument (or fifth, sixth ....) like:

     services:
       sonata.admin.category:
        class: Admin\AdminBundle\Admin\Category
        tags:
             - {name: sonata.admin, manager_type: orm, group: "Content", label: "Kategoria"}
         arguments:
             - ~ 
             - Admin\AdminBundle\Entity\Category
             - ~
             - @doctrine.orm.default_entity_manager
    calls:
        - [ setTranslationDomain, [AdminAdminBundle]]
    

    And then in your admin class you have to update override constructor, like :

     public function __construct($code, $class, $baseControllerName, $yourManager)
     {
         parent::_construct($code, $class, $baseControllerName);
         $this->yourManager = $yourManager
     }
    

    0 讨论(0)
提交回复
热议问题