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 — adding posts to the user profile

Now that we have done all of the heavy lifting to get our user's posts, we just have a few more lines of code until we can have them show up in the user profile. Let's start by adding some code in our index.php file to accept the username from the route, pass it to the get_posts_by_user function, and pass the data to the profile view:

  1. Open index.php, find the /user/:username route, and add the following code to pass the returned posts from our get_posts_by_user function to a variable for our view to access:
    get('/user/:username', function($app) { $app->set('user', User::find_by_username($app- >request('username'))); $app->set('is_current_user', ($app->request('username') == User::current_user() ...

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