我一直在扩展 ZfcUser 我让新字段正常工作,并且它们正在通过学说 2 添加到数据库中,没有问题。但现在我需要在用户和支付表和特殊角色系统之间添加一个链接。我试图将其放入事件中,但我无法保留教义服务。我的 onBootstrap 看起来像这样。
public function onBootstrap( MVCEvent $e )
{
$eventManager = $e->getApplication()->getEventManager();
$em = $eventManager->getSharedManager();
$em->attach(
'ZfcUser\Form\RegisterFilter',
'init',
function( $e )
{
$filter = $e->getTarget();
// do your form filtering here
new Register\Filter($filter);
}
);
// custom form fields
$em->attach(
'ZfcUser\Form\Register',
'init',
function($e)
{
/* @var $form \ZfcUser\Form\Register */
$form = $e->getTarget();
new Register\Form($form);
}
);
// here's the storage bit
$zfcServiceEvents = $e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();
$doctrineObjectManager = $e->getApplication()->getServiceManager()->get('Doctrine\ORM\EntityManager');
var_dump($e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager()->getEvents());
$zfcServiceEvents->attach('register', function($e){
/* @var $user \User\Entity\User */
//$form = $e->getParam('form');
//print_r($form);
//echo get_class($e);
new Register\Storage($e);
break;
});
// you can even do stuff after it stores
$zfcServiceEvents->attach('register.post', function($e) {
/*$user = $e->getParam('user');*/
});
}
表单和过滤器有效,但我无法从匿名事件函数中访问 docrtine 服务。我该怎么做呢?