I want to change from the default em to an em called \'ps\'. The configuration is correct and in the controller I can simply type $this->getManager(\'ps\')->getC
If your service class just needs the connection then it easiest way it make your own connection class and inject it.
namepace AppBundle\Connection;
class PsConnection extends Doctrine\DBAL\Connection
{
}
# doctrine.yaml
doctrine:
dbal:
connections:
ps:
wrapper_class: AppBundle\Connection\PsConnection
class HilaService
{
public function __construct(AppBundle\Connection\PsConnection $conn)
Everything will work as before but you can get the connection directly.
if you really do need the entity manager then you can make a service definition:
# services.yaml
AppBundle\Service\HilaService:
$entityManager: '@doctrine.orm.ps_entity_manager'
Finally, if you don't want to fool around with any of this stuff you can inject the ManagerRegistry and pull what you need from it.
class HilaService
{
public function __construct(Doctrine\Common\Persistence\ManagerRegistry $managerRegistry)
{
$em = $managerRegistry->getManager('ps'); // or getConnection()