在这个http://codeigniter.com/user_guide/libraries/parser.html教程中,我们有这个多维数组
$data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading',
'blog_entries' => array(
array('title' => 'Title 1', 'body' => 'Body 1'),
array('title' => 'Title 2', 'body' => 'Body 2'),
array('title' => 'Title 3', 'body' => 'Body 3'),
array('title' => 'Title 4', 'body' => 'Body 4'),
array('title' => 'Title 5', 'body' => 'Body 5')
)
);
我们像这样轻松打印他
{blog_entries}
<h5>{title}</h5>
<p>{body}</p>
{/blog_entries}
但是如何输出这样的数组http://i.imgur.com/L6i1B.png :?
$data = array(
array(
'user' => array('id' => "1", 'name' => "Test1"
),'title' => 'Title 1', 'body' => 'Body 1'),
array(
'user' => array('id' => "2", 'name' => "Test2"
),'title' => 'Title 2', 'body' => 'Body 2'),
array(
'user' => array('id' => "3", 'name' => "Test3"
),'title' => 'Title 3', 'body' => 'Body 3')
);
如果我们尝试做这样的事情
{blog_entries}
{user}
{id}
{/user}
{title}
{body}
<br />
{/blog_entries}
我们会有错误:
Message: Invalid argument supplied for foreach()
啊,在这里找到了类似的问题Extended Template Parser: CodeIgniter... Issue with Nested Arrays