The code for listing posts sits directly inside the profile.php
page, which was fine up until now. However, in a moment, we'll want to be able to display posts via callback
from Javascript, which on if we're not careful, could mean duplicate code or inconsistent layout. Let's safeguard ourselves against that by moving our code into a partial view that we can reuse easily.
1. Create a new file called
_posts.php
in views/user.2. Copy and paste the
foreach
code that lists out posts fromviews/user/profile.php
, and paste it into our new file_posts.php
. The end result of_posts.php
should as follows:<?php foreach ($posts as $post): ?> <div class="post-item row"> <div class="span7"> <strong><?php echo $user->name; ?></strong> <p> <?php echo $post->content; ?> </p> <?php echo $post->date_created; ?> </div> <div class="span1...