dongsui8162 2014-05-22 10:00
浏览 26

Cakephp 2.0使用flash消息注销

My Logout function is working very well with only return $this->redirect($this->Auth->logout());.

But how could I make a logout function with a Flash message? I tried this function. It doesn't work. I'm always login and it doesn't show me message:(

public function logout() {
    if ($this->Auth->user('logged_in')) {
        $this->Session->setFlash(__('you are logout'), 'default', array('class' => 'alert alert-success'));
        return $this->redirect($this->Auth->logout());
    } else {
        $this->Session->setFlash(__('you aren\'t logout, Please, try again'), 'default', array('class' => 'alert alert-danger'));
    }
}
  • 写回答

1条回答 默认 最新

  • duan0818 2014-05-22 14:30
    关注

    Inside the documentation says that if you want to create a custom message do by in /app/View/Elements. If you want your personalized message is not the way to go.

    in your /app/View/Elements/defaul.ctp

    $this->Session->setFlash(__('you are logout'), 'default', array('class' => 'alert alert-success'));
    

    afte in your cont roller

    public function logout() {
        if ($this->Auth->user('logged_in')) {
            $this->Session->setFlash('something', 'default');
            return $this->redirect($this->Auth->logout());
        } else {
            $this->Session->setFlash(__('you aren\'t logout, Please, try again'), 'default', array('class' => 'alert alert-danger'));
        }
    }
    

    you could also do it through a component

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错