我希望在没有 url 重定向的情况下在被访问的页面上显示登录表单。是否可以在 Module.php 中转发路由,即如果客户端访问 /stations/ 将其转发到“用户/登录”路由?没有外部重定向,我只想在私人页面上查看登录表单。
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;
}
此代码抛出Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Could not find prototype with name zfcuser/login'
.
所以问题如下:如何在 Module.php 中替换路由?