douzhang5295 2014-04-10 15:18
浏览 57
已采纳

我应该如何在菜单栏中创建一个由视图助手呈现的注销按钮?

I have a subnav bar in my module created from a view partial via a helper.

Here is the config in module.config.php:

'navigation' => array(
    'default' => array(
        array(
            'label' => 'Create',
            'route' => 'mymodule\Create',
        ),
        array(
            'label' => 'View',
            'route' => 'mymodule\view',
        ),
        array(
            'label' => 'Search',
            'route' => 'mymodule\search',
        ),
        array(
            'label' => 'Log Off',
            'route' => 'mymodule\logoff',
        ),
    ),
),

);

So here is my problem, I don't just want to redirect the user to the login page, I want to clear their session and THEN redirect them to the login page. I also don't want to have the login page just clear the session whenever a user navigates to it (in case they logged in and clicked the back button accidentally).

So what is the best way to handle this with my current config? I was thinking I could have my view helper that renders the partial set a flag in the session which the logon page would read and act accordingly- it would check for a "logoffButtonPress" flag in the session or something. But is it appropriate to do something like this in a view helper? Is this even possible in a view helper?

  • 写回答

2条回答 默认 最新

  • dtgr3392 2014-04-10 15:26
    关注

    Why not just have the button target a logoutAction?

    I'm using BjyAuthorise and ZfcUser modules but the process of clearing the session and redirecting is the same.

    LoginController

    public function logoutAction()
    {
        $this->authService->logout();
    
        $redirect = $this->params('redirect', false);
    
        if ($redirect) {
            return $this->redirect()->toUrl($redirect);
        }
    
        return $this->redirect()->toRoute(
            $this->config->getLogoutRedirectRoute()
        );
    }
    

    AuthService

    public function logout()
    {
        $adapter = $this->authService->getAdapter();
    
        $adapter->resetAdapters();
        $adapter->logoutAdapters();
    
        $this->authService->clearIdentity();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀