title: How to pass database record from Controller to View in CakePHP
body: <p>I've started a project in CakePHP. I have no experience of it, most of my experience is with Symfony2.</p>
  
  <p>Right now, I have built a view file, a controller, and a model for use with this project and it's database. In one controller I want to pass one record from the database to the view for use on the homepage. However, I'm unable to pass the record as I get this error:</p>
  
  <blockquote>
    <p>Notice (8): Undefined variable: content [APP\View\Contents\home.ctp,
    line 42]</p>
  </blockquote>
  
  <p>Here is my controller code:</p>
  
  <pre><code>function home() {
      $content = $this-&gt;Content-&gt;query("SELECT title, content FROM content WHERE id = 1;");
      $this-&gt;set('pagecontent',$content); 
  }
  </code></pre>
  
  <p>And here is the code I'm using to display the data in the view file:</p>
  
  <pre><code>&lt;?php $content['content']; ?&gt;
  </code></pre>
  
  <p>What have I missed?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  I have changed the <code>&lt;?php $content['content']; ?&gt;</code> to  <code>&lt;?php echo $pagecontent['Content']['content']; ?&gt;</code> inline with the changes outlined in the answer from Ross. However, there is now this error:</p>
  
  <blockquote>
    <p>Notice (8): Undefined index: Content [APP\View\Contents\home.ctp, line
    43]</p>
  </blockquote>
  
  <p>I have used the <code>&lt;?php echo debug($this-&gt;viewVars); ?&gt;</code> and this is the output from that:</p>
  
  <pre><code> app\View\Contents\home.ctp (line 42) Array (
       [pagecontent] =&gt; Array
           (
               [0] =&gt; Array
                   (
                       [content] =&gt; Array
                           (
                               [title] =&gt; &lt;h1&gt;This is a title&lt;/h1&gt;
                               [content] =&gt; &lt;p&gt;this is some test text&lt;/p&gt;
                           )
  
                   )
  
           )
  
   )
  </code></pre>