我的班级(帖子.php):
class Posts {
private function getPosts() {
$get_post = (new MYSQL) -> getAllPosts(); // here get all posts from my db
$GLOBALS["all_posts"] = $get_posts;
function all_posts() {
// When I use the return, the page enter on one infinite bucle.. If I use echo this doesnt happen.
return $GLOBALS["all_posts"];
}
}
}
我希望在我的内容中.php我可以调用all_posts()函数来获取数组并像这样打印:
<div class="posts">
<?php foreach(all_posts() AS $post) : ?>
<h1><?php echo $post["title"]</h1>
<p><?php echo $post["content]; ?></p>
<?php endforeach; ?>
</div>
我希望函数all_posts()可以加载到我的内容中.php;在我的索引.php,在包含页眉.php,内容.php和页脚之前.php我加载Post->getPosts()。谢谢你。
万千封印