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 — creating a route for user profiles

We are going to create a route so that people can see a profile by going to a unique URL. This will be the first time that we'll really utilize our routing system's ability to handle route variables.

  1. Open index.php, and create a get route for a user profile by entering the following code:
    get('/user/:username', function($app) {
    });
    
  2. Let's use the route variable :username to tell us the username that we want to find; we'll pass this to the get_by_username function we created in the User class. Finally, we'll pass the returned user object to the view in the user variable:
    get('/user/:username', function($app) {
    $app->set('user', User::get_by_username($app- >request('username')));
    
    });
    
  3. Lastly, we'll ...

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