title: Call to a member function allow() on a non-object - authorization
body: <p>I used this tutorial: <a href="http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html" rel="noreferrer">http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html</a></p>
  
  <p>To build my first form/create user app, but it fails with an error message:</p>
  
  <pre><code>Fatal error: Call to a member function allow() on a non-object in /home/public_html/cake/app/Controller/UsersController.php on line 18
  </code></pre>
  
  <p>This ius the 18 line:</p>
  
  <pre><code>$this-&gt;Auth-&gt;allow('add', 'logout');
  </code></pre>
  
  <p>The above line is a member of function:</p>
  
  <pre><code>public function beforeFilter() {
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('add', 'logout');
  }
  </code></pre>
  
  <p>My whole <code>UsersController.php</code>:</p>
  
  <pre><code>&lt;?php
  class UsersController extends AppController {
  
      public function login() {
          if ($this-&gt;Auth-&gt;login()) {
              $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
          } else {
              $this-&gt;Session-&gt;setFlash(__('Invalid username or password, try again'));
          }
      }
  
      public function logout() {
          $this-&gt;redirect($this-&gt;Auth-&gt;logout());
      }
  
      public function beforeFilter() {
          parent::beforeFilter();
          $this-&gt;Auth-&gt;allow('add', 'logout');
      }
  
      public function index() {
          $this-&gt;User-&gt;recursive = 0;
          $this-&gt;set('users', $this-&gt;paginate());
      }
  
      public function view($id = null) {
          $this-&gt;User-&gt;id = $id;
          if (!$this-&gt;User-&gt;exists()) {
              throw new NotFoundException(__('Invalid user'));
          }
          $this-&gt;set('user', $this-&gt;User-&gt;read(null, $id));
      }
  
      public function add() {
          if ($this-&gt;request-&gt;is('post')) {
              $this-&gt;User-&gt;create();
              if ($this-&gt;User-&gt;save($this-&gt;request-&gt;data)) {
                  $this-&gt;Session-&gt;setFlash(__('The user has been saved'));
                  $this-&gt;redirect(array('action' =&gt; 'index'));
              } else {
                  $this-&gt;Session-&gt;setFlash(__('The user could not be saved. Please, try again.'));
              }
          }
      }
  
      public function edit($id = null) {
          $this-&gt;User-&gt;id = $id;
          if (!$this-&gt;User-&gt;exists()) {
              throw new NotFoundException(__('Invalid user'));
          }
          if ($this-&gt;request-&gt;is('post') || $this-&gt;request-&gt;is('put')) {
              if ($this-&gt;User-&gt;save($this-&gt;request-&gt;data)) {
                  $this-&gt;Session-&gt;setFlash(__('The user has been saved'));
                  $this-&gt;redirect(array('action' =&gt; 'index'));
              } else {
                  $this-&gt;Session-&gt;setFlash(__('The user could not be saved. Please, try again.'));
              }
          } else {
              $this-&gt;request-&gt;data = $this-&gt;User-&gt;read(null, $id);
              unset($this-&gt;request-&gt;data['User']['password']);
          }
      }
  
      public function delete($id = null) {
          if (!$this-&gt;request-&gt;is('post')) {
              throw new MethodNotAllowedException();
          }
          $this-&gt;User-&gt;id = $id;
          if (!$this-&gt;User-&gt;exists()) {
              throw new NotFoundException(__('Invalid user'));
          }
          if ($this-&gt;User-&gt;delete()) {
              $this-&gt;Session-&gt;setFlash(__('User deleted'));
              $this-&gt;redirect(array('action'=&gt;'index'));
          }
          $this-&gt;Session-&gt;setFlash(__('User was not deleted'));
          $this-&gt;redirect(array('action' =&gt; 'index'));
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Why does it happends?</p>