title: CakePHP passing data to element
body: <p>I have the following code in my controller:</p>
  
  <pre><code>function index()
  {
      $posts = $this-&gt;set('posts', $this-&gt;Portfolio-&gt;find('all'));
  
      if (isset($this-&gt;params['requested']))
      {
          return $posts;
      }
      else
      {
          $this-&gt;set('posts', $this-&gt;Portfolio-&gt;find('all'));
      }
  }
  </code></pre>
  
  <p>and what I want it to do is a) show a list of portfolio items for the index e.g. <code>/portfolio/</code> and b) show a list of portfolio items inside an element so a user can access the portfolio items from my sidebar across the site.</p>
  
  <p>Here is my element for the sidebar:</p>
  
  <pre><code>&lt;?php $posts = $this-&gt;requestAction('portfolio/index'); ?&gt;
  &lt;ul&gt;
      &lt;?php foreach ($posts as $post): ?&gt;
      &lt;li&gt;&lt;?php echo $this-&gt;Html-&gt;link($post['Portfolio']['title'], array('action' =&gt; 'view', $post['Portfolio']['id']));?&gt;&lt;/li&gt;
      &lt;?php endforeach; ?&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>and then I call it like so in my layout:</p>
  
  <pre><code>&lt;?php $this-&gt;element('portfolio-nav', array('posts' =&gt; $posts) ); ?&gt;
  </code></pre>
  
  <p>However it gives the following error:</p>
  
  <pre><code>Notice (8): Undefined variable: posts [APP/controllers/portfolio_controller.php, line 16]
  </code></pre>
  
  <p>And doesn't show the list of items in the sidebar.</p>
  
  <p>I'm pretty sure what I have written in my controller is garbage, so if anyone can help me get it working, that'd be awesome.</p>
  
  <p>Thanks</p>