0
我的用户需要确认他们的电子邮件地址才能访问该应用程序。ZF2 - BootStrap重定向
我有一个特定的路由,如果他们登录并且他们的电子邮件没有被确认:“customer/register-landing”,这将发送一封电子邮件,视图将解释他们需要做什么。
为简洁起见,我使用了bootstrap。
这是我迄今为止最后一点,我努力工作了(再直接参与)
//I run console related queries and this breaks if run
if ($e->getRequest() instanceof \ZF\ContentNegotiation\Request)
{
//Get a user object
$authService = $sm->get(AuthorizationService::class);
$userObject = $authService->getIdentity();
if (!$userObject instanceof User) {
return;
}
if ($userObject->getIsEmailConfirmed() == 1) {
return;
}
//So we have a logged in user who needs to confirm their email
$redirect = $em->attach(MvcEvent::EVENT_DISPATCH,
function($e){
$route = $e->getRouteMatch();
if ($route->getMatchedRouteName() != 'customer/register-landing')
{
//Redirect to the route: customer/register-landing
}
}
);
}
什么我需要做重新定向到实际的页面?我周围一看,我发现这个代码:
$em->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controller->plugin('redirect')->toRoute('customer/register-landing');
}, 100);
然而,当我将它添加到类它不工作:
$redirect = $em->attach(MvcEvent::EVENT_DISPATCH,
function($e){
$route = $e->getRouteMatch();
if ($route->getMatchedRouteName() != 'customer/register-landing')
{
$em->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controller->plugin('redirect')->toRoute('customer/register-landing');
}, 100);
}
}
);
什么是做这种正确的方法是什么?