How to define/pass the entity manager for sonata-admin

11,744

Solution 1

What was missing in my config.yml was:

doctrine:
  [...]
  orm:
    [...]
    entity_managers:
      default:
        mappings:
          ApplicationSonataUserBundle: ~
          SonataUserBundle: ~

Solution 2

When you use php app/console sonata:admin:generate it requests for fully qualified model class, so you'd write something like: \Acme\DemoBundle\Entity\DemoEntity

the problem is, that when generator creates service for you it adds line: arguments: [~, \Acme\DemoBundle\Entity\DemoEntity, AcmeDemoBundle:DemoEntityAdmin]

That breaks it.

It works with: arguments: [~, Acme\DemoBundle\Entity\DemoEntity, AcmeDemoBundle:DemoEntityAdmin]

Notice missing "\" before Acme\Demo....

Solution 3

Just had this problem.

Make sure you easy-extended the SonataUserBundle:

php app/console sonata:easy-extends:generate SonataUserBundle

and are loading it in AppKernel.php

new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),

See documentation here: https://github.com/sonata-project/SonataUserBundle/blob/master/Resources/doc/reference/installation.rst

Then the automapping is enough and you don't need to define manual mapping.

Share:
11,744
Andresch Serj
Author by

Andresch Serj

Senior Full-Stack Developer that loves Angular/Typescript/NestJs and Bicycles. Loves Test Driven, Domain Driven, Component Driven and even Behaviour Driven. Loves T-Shaped Teams.

Updated on June 05, 2022

Comments

  • Andresch Serj
    Andresch Serj almost 2 years

    I followed this tutorial to install SonataAdmin with FOSUserBundle.

    Now i keep getting this Error Message: No entity manager defined for class Application\Sonata\UserBundle\Entity\User

    But how do i set/pass the EntityManager? I haven't found anything about configuring it or any hint on what this error means. Any help anyone?


    Edit #1:

    As asked for, here is what i have in my config.yml for sonata so far:

    sonata_block:
        default_contexts: [cms]
        blocks:
            sonata.admin.block.admin_list:
                contexts:   [admin]
            sonata.block.service.text:
            sonata.block.service.rss:
    

    Edit #2:

    I added the entity manager configuration part for Doctrine2 ORM Admin thou it is mentioned in the Documentation that if left null, it should just use the default. Still, it doesn't solve my problem.

    sonata_doctrine_orm_admin:
        # default value is null, so doctrine uses the value defined in the configuration
        entity_manager: '@doctrine.orm.entity_manager'
    

    Edit #3: I did set auto_mapping to true as well, even thou that also is true by default. Still no Solution to this Problem.

  • Andresch Serj
    Andresch Serj about 10 years
    i gave up on the Admin Bundle long time ago. Thanks for the delated answer to an already answered question thou. In my next symfony project i will try your solution.