sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Fatal error: Call to a member function getMetadataFactory() on a non-object #694

Closed gavinwilliams closed 12 years ago

gavinwilliams commented 12 years ago

I'm trying to create a new admin section in Sonata admin. I have a model with XML mapping and am passing it to the admin service with the following XML.

    <services>

        <service id="application.menu.admin.menu" class="Application\MenuBundle\Admin\MenuAdmin">
            <tag name="sonata.admin" manager_type="orm" group="Menu" label="Menu" />
            <argument />
            <argument>Application\MenuBundle\Entity\Menu</argument>
            <argument>SonataAdminBundle:CRUD</argument>
            <call method="setTranslationDomain">
                <argument>Menu Admin</argument>
            </call>
        </service>

    </services>

When I attempt to view the page in SonataAdmin I get the following error.

Fatal error: Call to a member function getMetadataFactory() on a non-object in /vagrant/vendor/bundles/Sonata/DoctrineORMAdminBundle/Model/ModelManager.php on line 53

I've cleared the cache and this happens in the dev environment.

Any help would be greatly appreciated.

gavinwilliams commented 12 years ago

Never mind, found it. It should be clear somewhere in the documentation that if you create a new bundle, you need to add

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    YourBundleName: ~

To your configuration file in order for SonataAdmin to make use of the getEntityManagerForClass method for multiple entity managers.