我在让它工作时遇到了一些问题,我确信有一个简单的解释,但我目前无法连接这些点。
我在 Twitter Bootstrap 中使用 Yii Framework 1.1.13。
我的控制器如下所示:
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));
}
视图如下所示:
/* @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);
...
其中显示以下内容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
但是当我做 a 时$comment['rating']
,它会返回一个错误:
Undefined index: rating
有人知道我做错了什么吗?