cakePHP checking authentication if logged in


It has been difficult to understand all the components for checking authntication before displaying the page.

One options that seems to work well for cake PHP 2.4x

under Config in the boostrap file add:

  • App::uses('AuthComponent', 'Controller/Component');

In the controller for example add

        if (AuthComponent::user('id_user')){            $this->set('companies', $this->paginate());        }else{            $this->redirect(array('controller' => 'users', 'action' => 'login'));        }

2015-01-11 10:28:48gstlouis