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