title: CakePhp Error: Call to a member function create() on a non-object
body: <p>I am currently learning how to use CakePhp.</p>
  
  <p>I have created a function in my custom controller as follows:</p>
  
  <pre><code>class FormatsController extends AppController
  {
      // ....
  
      function admin_add()
      {
  
          // if the form data is not empty
          if (!empty($this-&gt;data)) {
              // initialise the format model
              $this-&gt;Format-&gt;create();
              // create the slug
              $this-&gt;data['Format']['slug'] = $this-&gt;slug($this-&gt;data['Format']['name']);
              // try saving the format
              if ($this-&gt;Format-&gt;save($this-&gt;data)) {
                  // set a flash message
                  $this-&gt;Session-&gt;setFlash('The Format has been saved', 'flash_good');
                  // redirect
                  $this-&gt;redirect(array('action' =&gt; 'index'));
              } else {
                  // set a flash message
                  $this-&gt;Session-&gt;setFlash('The Format could not be saved. Please, try again.', 'flash_bad');
              }
          }
      }
  
  }
  </code></pre>
  
  <p>However in my view I am getting this error:</p>
  
  <blockquote>
    <p>Error: Call to a member function create() on a non-object</p>
  </blockquote>
  
  <p>Why is this error caused and how can I fix it?</p>
  
  <p>My apologies, I believe the line it is referencing is <em>not</em> in the Controller but in my view itself. It refers to my view which has the following line:</p>
  
  <pre><code>&lt;?php echo $form-&gt;create('Format');?&gt;
  </code></pre>
  
  <p>Is there something else I need to declare before using this? i.e. <code>$this-&gt;Format-&gt;create();</code></p>