I'm having some problems getting this to work, I am sure there's an easy explanation, but I am not able to connect the dots at the moment.
I'm using Yii Framework 1.1.13 with the Twitter Bootstrap.
My controller looks like this:
public function actionIndex()
{
$posts = array(
'total' => 5,
'items' => array(
array(
'id' => 1,
'header' => 'Praesent arcu nisi',
'body' => 'Lacinia a dolor at, tempus suscipit diam.Lacinia a dolor at, tempus suscipit diam.Lacinia a dolor at, tempus suscipit diam.Lacinia a dolor at, tempus suscipit diam.Lacinia a dolor at, tempus suscipit diam.',
'img' => '',
'link' => 'http://www.example.com',
'category' => 'Test',
'company' => 'Example',
'company_bkg' => '',
'rating' => 8,
'comments_total' => 2,
'comments_items' => array(
array(
'id' => 1,
'name' => 'Anonymous',
'timestamp' => date('d.m.Y H:i'),
'text' => 'Kommentar 1.',
'rating' => 145,
),
array(
'id' => 2,
'name' => 'Example',
'timestamp' => date('d.m.Y H:i'),
'text' => 'Kommentar 2.',
'rating' => -29,
),
),
),
array(
'id' => 2,
'header' => 'Lacinia a dolor at',
'body' => 'Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi.',
'img' => '',
'link' => 'http://www.example.com',
'category' => 'Test',
'company' => 'Example',
'company_bkg' => '',
'rating' => 0,
'comments_total' => 0,
'comments_items' => array(
array(
),
),
),
array(
'id' => 3,
'header' => 'Lacinia a dolor at',
'body' => 'Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi. Praesent arcu nisi.',
'img' => '',
'link' => 'http://www.example.com',
'category' => 'Test',
'company' => 'Example',
'company_bkg' => '',
'rating' => -8,
'comments_total' => 1,
'comments_items' => array(
array(
'id' => 1,
'name' => 'Anonymous',
'timestamp' => date('d.m.Y H:i'),
'text' => 'Kommentar 1.',
'rating' => 9,
),
),
),
),
);
$this->render('index',array('posts'=>$posts));
}
And the view looks like this:
/* @var $this SiteController */
/* @var $posts array */
/* @var $comment array */
...
foreach($posts['items'] as $post) {
...
for($i = 0; $i < $length; $i++) {
$comment = $post['comments_items'][$i];
var_dump($comment);
...
Which shows the following var_dump
:
array (size=5)
'id' => int 1
'name' => string 'Anonymous' (length=9)
'timestamp' => string '29.06.2013 15:57' (length=16)
'text' => string 'Kommentar 1.' (length=12)
'rating' => int 145
But when I do a $comment['rating']
, it comes back with an error:
Undefined index: rating
Anyone have any idea what I'm doing wrong?