I'm using cakephp 2.2.5 for this.
I've got a contained find in one controller that pulls a list of four news items from a 'has many' relationship.
I'm trying to produce a list of these four items, but can't seem to get the php foreach loop working.
the controller array is this:
$newsLists = $this->Industry->find('all', array(
'conditions' => array('id' => $id),
'fields' => array('id'),
'contain' => array(
'News' => array(
'conditions' => array('News.type' => 'main','News.active' => 'Yes'),
'fields' => array(
'News.type',
'News.id',
),
'order' => array(
'News.created' => 'desc',
),
'limit' => 3
))));
$this->set('newsLists', $newsLists);
The debug output works fine:
Array
(
[0] => Array
(
[Industry] => Array
(
[id] => 1
[tags] =>
)
[News] => Array
(
[0] => Array
(
[type] => main
[id] => 10
[industry_id] => 1
)
[1] => Array
(
[type] => main
[id] => 11
[industry_id] => 1
)
[2] => Array
(
[type] => main
[id] => 12
[industry_id] => 1
)
)
)
)
but this foreach loop only display one item:
<ul>
<?php
$i = 0;
foreach ($newsLists as $newsList): ?>
<li><?php echo $newsList['News'][$i]['slug']; ?></li>
<?php endforeach; ?>
thanks