I have the following code in my controller:
function index()
{
$posts = $this->set('posts', $this->Portfolio->find('all'));
if (isset($this->params['requested']))
{
return $posts;
}
else
{
$this->set('posts', $this->Portfolio->find('all'));
}
}
and what I want it to do is a) show a list of portfolio items for the index e.g. /portfolio/
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.
Here is my element for the sidebar:
<?php $posts = $this->requestAction('portfolio/index'); ?>
<ul>
<?php foreach ($posts as $post): ?>
<li><?php echo $this->Html->link($post['Portfolio']['title'], array('action' => 'view', $post['Portfolio']['id']));?></li>
<?php endforeach; ?>
</ul>
and then I call it like so in my layout:
<?php $this->element('portfolio-nav', array('posts' => $posts) ); ?>
However it gives the following error:
Notice (8): Undefined variable: posts [APP/controllers/portfolio_controller.php, line 16]
And doesn't show the list of items in the sidebar.
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.
Thanks
See Question&Answers more detail:os