title: Cake PHP registration form
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/54566/call-to-a-member-function-on-a-non-object">Call to a member function on a non-object</a>  </p>
  </blockquote>
  
  
  
  <p>I have just started learning cake php and am attempting to create a very simple registration form consisting of one field. I'm having trouble interacting with my model however. Code below:</p>
  
  <p>This is my Register Controller:</p>
  
  <pre><code>class RegisterController extends AppController{
  
      public $helpers = array('Form', 'Html', 'Js');
  
      public function index(){
  
      }
  
  }
  </code></pre>
  
  <p>This is my register controllers index.ctp view:</p>
  
  <pre><code>echo $this-&gt;Form-&gt;create('Users', array('controller' =&gt; 'Users', 'action' =&gt; 'createUser'));
  echo $this-&gt;Form-&gt;input('username');
  echo $this-&gt;Form-&gt;end('Register');
  </code></pre>
  
  <p>I then created a UsersController.php file and a Users.php (model) file to handle the validation and saving of the form data.</p>
  
  <p>UsersController.php:</p>
  
  <pre><code>class UsersController extends AppController{
  
  
      public function createUser(){
  
          $this-&gt;Users-&gt;create();
  
          $this-&gt;Users-&gt;save($this-&gt;Request-&gt;data);
  
      }
  
  }
  </code></pre>
  
  <p>And the Users.php model file:</p>
  
  <pre><code>class Users extends AppModel {
  
      public $validation = array(
  
          'username' =&gt; array(
  
              'rule1' =&gt; array(
                  'rule' =&gt; 'isUnique',
                  'message' =&gt; 'That username is already taken'
                  ),
              'rule2' =&gt; array(
  
                  'rule' =&gt; 'nonEmpty',
                  'message' =&gt; 'This field cannot be empty',
                  'required' =&gt; true
  
              )
          )
      );
  
  }
  </code></pre>
  
  <p>Whenever I hit the 'register' button on my form however, I get the following error:</p>
  
  <pre><code>Call to a member function create() on a non-object
  </code></pre>
  
  <p>It's referring to the following line in my UsersController.php file:</p>
  
  <pre><code>$this-&gt;Users-&gt;create();
  </code></pre>
  
  <p>I have a users table created in my cake database that the php files can see it. I don't understand why my UsersController.php file can't write to its model?</p>