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 calledget_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 get_by_username($username = null) { }
3. Now, let's set the database to instantiate Bones and a proxy Sag. Remember, we're dealing with the
_users
database, so we'll need to log in with theadmin
privileges.public static function get_by_username...