Zend framework2 Zend 2 redirect()模块错误

Zend framework2 Zend 2 redirect()模块错误,zend-framework2,Zend Framework2,我做了一个checklogin函数来检查$auth->getIdentity(),,但我得到了以下错误: 致命错误:在中调用未定义的方法Admin\Module::redirect() 第51行的C:\xampp\websites\zend2\module\Admin\module.php 我怎样才能解决这个问题 public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication

我做了一个checklogin函数来检查
$auth->getIdentity(),
,但我得到了以下错误:

致命错误:在中调用未定义的方法Admin\Module::redirect() 第51行的C:\xampp\websites\zend2\module\Admin\module.php

我怎样才能解决这个问题

public function onBootstrap(MvcEvent $e)
{

    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
    $app = $e->getParam('application');
    $app->getEventManager()->attach('render', array($this, 'setLayoutTitle'));

    $moduleRouteListener->attach($eventManager);

    // add event
    $eventManager->attach('render', array($this, 'checklogin')); 


}


public function checkLogin()
{   
    $auth = new AuthenticationService();
    if( $auth->getIdentity() == NULL ){
        return $this->redirect()->toRoute('/admin/login');  
    }else{
       return $this->redirect()->toRoute('/admin'); 
    }
}

这是因为
模块
类中没有
重定向
方法

我建议将此签入
dispatch
事件,因为
dispatch
事件是在调度控制器操作之前触发的

因此,您需要更改onBootstrap模块方法中的侦听器方法设置:

public function onBootstrap(MvcEvent $e)
{
    // ...
    $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'checkLogin'));
    // ...
}
然后在侦听器方法中,您得到了
MvcEvent
,其中
target
是匹配的控制器类:

public function checkLogin(MvcEvent $e)
{
    $controller = $e->getTarget();
    if ($someCondition) {
        return $controller->plugin('redirect')->toRoute('your/route/name');
    }
}

这是因为
模块
类中没有
重定向
方法

我建议将此签入
dispatch
事件,因为
dispatch
事件是在调度控制器操作之前触发的

因此,您需要更改onBootstrap模块方法中的侦听器方法设置:

public function onBootstrap(MvcEvent $e)
{
    // ...
    $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'checkLogin'));
    // ...
}
然后在侦听器方法中,您得到了
MvcEvent
,其中
target
是匹配的控制器类:

public function checkLogin(MvcEvent $e)
{
    $controller = $e->getTarget();
    if ($someCondition) {
        return $controller->plugin('redirect')->toRoute('your/route/name');
    }
}

这是因为
模块
类中没有
重定向
方法

我建议将此签入
dispatch
事件,因为
dispatch
事件是在调度控制器操作之前触发的

因此,您需要更改onBootstrap模块方法中的侦听器方法设置:

public function onBootstrap(MvcEvent $e)
{
    // ...
    $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'checkLogin'));
    // ...
}
然后在侦听器方法中,您得到了
MvcEvent
,其中
target
是匹配的控制器类:

public function checkLogin(MvcEvent $e)
{
    $controller = $e->getTarget();
    if ($someCondition) {
        return $controller->plugin('redirect')->toRoute('your/route/name');
    }
}

这是因为
模块
类中没有
重定向
方法

我建议将此签入
dispatch
事件,因为
dispatch
事件是在调度控制器操作之前触发的

因此,您需要更改onBootstrap模块方法中的侦听器方法设置:

public function onBootstrap(MvcEvent $e)
{
    // ...
    $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'checkLogin'));
    // ...
}
然后在侦听器方法中,您得到了
MvcEvent
,其中
target
是匹配的控制器类:

public function checkLogin(MvcEvent $e)
{
    $controller = $e->getTarget();
    if ($someCondition) {
        return $controller->plugin('redirect')->toRoute('your/route/name');
    }
}

这就是我要找的,thnx!这就是我要找的,thnx!这就是我要找的,thnx!这就是我要找的,thnx!