Check if the user is logged into the view

How can I check if the user is logged in the system?

I’m using auth.

I would like to check if the user is logged into the view… to display a logout button

The code in view:

<?php if($isLogged): ?>
     <?php echo $this->Html->link(__('Logout'), ['controller' => 'Users', 'action' => 'logout']); ?>
<?php endif; ?>

In UsersController my login()

public function login()
{
if($this->request->is(‘post’)) {
$user = $this->Auth->identify();
if($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__(‘Usuário ou senha inválidos, tente novamente!’));
}
}

It looks like your login code is successfully using $this->Auth->identify() to do the job. Why wouldn’t that work for your view also?