CakePHP check if user is logged in inside a view

前端 未结 12 1880
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 13:00

I have the following code:

    Auth->user())
    {
        echo $this->element(\'header\');
    }
    else
    {
        e         


        
12条回答
  •  时光说笑
    2020-12-24 13:23

    If it helps anyone out in cakephp version 3.7.8 session has been depriciated to getSession so to update Lee Nielsen's comment

    if (is_null($this->request->getSession()->read('Auth.User.username'))) {
    
    echo "....logged out";
    
    } else {
    
    echo "You are Logged in As " . $this->request->getSession()->read('Auth.User.username'); 
    
    }
    

提交回复
热议问题