dongwen2162 2014-09-06 19:39
浏览 30

Zend Framework 2使用站点URL在onBootStrap中重定向

I'm trying to redirect in Module.php in Zend Framework 2.

I got the code online and it is working but not as expected.

I'm trying to redirect to a different module.

Here is the code.

public function onBootStrap($e){
    $container = new Container();
    if(!$container || !$container->admin_id){
        //  Assuming your login route has a name 'login', this will do the assembly
        // (you can also use directly $url=/path/to/login)
        $url = $e->getRouter()->assemble(array('action' => 'login'), array('name' => 'admin'));
        $response->getHeaders()->addHeaderLine('Location', $url);
        // When an MvcEvent Listener returns a Response object,
        // It automatically short-circuit the Application running
        // -> true only for Route Event propagation see Zend\Mvc\Application::run

        // To avoid additional processing
        // we can attach a listener for Event Route with a high priority
        $stopCallBack = function($event) use ($response){
            return $response;
        //Attach the "break" as a listener with a high priority
        $e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $stopCallBack,-10000);
        return $response;

It works and redirects me to http://localhost/admin/login But my actual site url is http://localhost/MantissaAdmin/public/ So it should be redirecting me to http://localhost/MantissaAdmin/public/admin/login

How can I redirect to http://localhost/MantissaAdmin/public/admin/login ?

  • 写回答

1条回答 默认 最新

  • dp152153 2014-09-08 08:16

    I would suggest to grab the ZF2 redirect plugin from the controller and use this for redirecting to another route. You can check an example here in another question on StackOverflow.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 qt+ffmpeg报错non-existing PPS 0 referenced
  • ¥15 FOC simulink
  • ¥15 咨询一下有关于王者荣耀赢藏战绩
  • ¥50 MacOS 使用虚拟机安装k8s
  • ¥500 亚马逊 COOKIE我如何才能实现 登录一个亚马逊账户 下发新 COOKIE ..我使用下发新COOKIE 导入ADS 指纹浏览器登录,我把账户密码 修改过后,原来下发新COOKIE 不会失效的方式
  • ¥20 玩游戏gpu和cpu利用率特别低,玩游戏卡顿
  • ¥25 oracle中的正则匹配
  • ¥15 关于#vscode#的问题:把软件卸载不会再出现蓝屏
  • ¥15 vimplus出现的错误
  • ¥30 怎么使用AVL fire ESE软件自带的优化模式来优化设计Soot和NOx?