O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — taking posts out of profile.php and putting them in their own partial view

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 from views/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"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required