Getting instance of container in custom sonata block
问题 I am creating a custom block for dashboard and where I want to display information persisted into the DB. How do I get an instance of the container or doctrine entity manager in the block service? Tried googling alot but nothing substantial has come out so far 回答1: When you create a new block in sonata, you have to declare it like a service, so you can inject doctrine.orm.entity_manager . I can show you an example of a block where I injected the entity manager: //My\Bundle\Block