CakePHP check if user is logged in inside a view

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

I have the following code:

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


        
12条回答
  •  [愿得一人]
    2020-12-24 13:30

    To summarize the answers on this page, evaluate one of the following based on which version of CakePHP you are using:

    For version 1.x

    $this->Session->read('Auth.User')
    

    For version 2.x

    AuthComponent::user('id')
    

    For version 3.x

    $this->request->session()->read('Auth.User.id')
    

    For version 4.x, using the Authentication component

    $this->loadHelper('Authentication.Identity');
    ...
    $this->Identity->isLoggedIn()
    

提交回复
热议问题