问题描述
我想在页面显示登录表单而不URL重定向被访问。是否有可能在Module.php转发路径,即如果客户端访问/电台/转发给用户/密码路线?如果没有外部重定向,我只是想看看登录表单在私人网页。
I wish to show login form at page being accessed without url redirection. Is it possible to forward route at Module.php, i.e. if client accesses /stations/ forward it to "user/login" route? Without external redirect, I just want to see login form at private pages.
public function onBootstrap(MvcEvent $e){
# .... other
$eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'checkAuth'), -100);
}
public function checkAuth(MvcEvent $e){
# ... get auth service
if (!$auth->hasIdentity()) {
# smth like this
$router = $e->getRouter()->setRoutes(array('zfcuser/login'));
return $router;
}
return;
}
这code抛出未捕获的异常'的Zend \\的mvc \\路由器\\异常\\ RuntimeException的与消息无法找到原型名称zfcuser /登录
。
所以,问题如下:?我怎么能在Module.php替代路线
So the question is the following: how can I substitute route at Module.php?
推荐答案
这个问题已经解决了感谢@samsonasik评论另一个问题。
The problem has been solved thanks to @samsonasik comment to another question.
public function checkAuth(MvcEvent $e){
# ... get auth service
if (!$auth->hasIdentity()) {
$e->getRouteMatch()
->setParam('controller', 'zfcuser')
->setParam('action', 'login');
}
return;
}
所以,我已经改变了路线,无需外部重定向。
So I have changed route without external redirection.
这篇关于如何在Module.php转发到另一条路线,而不重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!