Since you're doing this in onBootstrap()
the MvcEvent
has everything you need. You just need to fetch the entity manager and use
it in your anonymous function
public function onBootstrap( MVCEvent $e )
{
$eventManager = $e->getApplication()->getEventManager();
$em = $eventManager->getSharedManager();
// fetch the entity manager
$sm = $e->getApplication()->getServiceManager();
$entityManager = $sm->get('Doctrine\ORM\EntityManager');
$em->attach(
'ZfcUser\Form\RegisterFilter',
'init',
// use the entity manager in your function
function( $e ) use ($entityManager);
{
$filter = $e->getTarget();
// variable $entityManager is now available in this scope
// so we could for example inject it into the filter like so
new Register\Filter($filter, $entityManager);
}
);
I'm assuming the entity manager was the doctrine service you were referring to, but it's the same methodology to use
other services in the scope of your anonymous functions.