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 — getting single user documents

As you might remember, in Chapter 3, Getting Started with CouchDB and Futon, we were able to retrieve a document from CouchDB just by passing the ID of the document we wanted. We are going to do the same thing this time to find a user's information using Sag. One important thing to note is that we'll have to make sure that when we look for users using their ID, we need to prepend it with the org.couchdb.user: namespace.

Let's start by opening classes/user.php and scrolling to the bottom.

  1. Add a public static function called get_by_username().
    public static function get_by_username() {
    }
    
  2. In order to find a user by ID, we need to allow our function to accept the parameter $username.
    public static function ...

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