可以说我有以下内容:
$categories = ORM::factory('category')->find_all();
foreach ($categories as $category) :
echo $category->category_title;
foreach ($category->posts->find_all() as $post) :
echo $post->post_title;
endforeach;
endforeach;
它打印:
Category One
Post One
Category Two
Category Three
Post Two
Category Four
Post Three
差距意味着那里没有帖子。
我想要它打印的是:
Category One
Post One
Category Two
No Post
Category Three
Post Two
Category Four
Post Three
所以基本上我想要:
foreach ($posts->find_all() as $post) :
if post exists
echo $post->post_title;
else
No Post
endforeach;
我怎么做?