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 support to get_posts_by_user in the post class

  1. Open classes/post.php in your text editor.
  2. Create a new public function called get_posts_by_user that will accept $username as a parameter.
    public function get_posts_by_user($username) {
    }
    
  3. Now, let's create a new instance of Bones, so that we can query CouchDB. Let's also instantiate an array called $posts, which we'll return at the end of this function.
    public function get_posts_by_user($username) {
    $bones = new Bones();
    $posts = array();
    return $posts;
    
    }
    
  4. Next, let's query our view by passing $username as the key, and let's use a foreach function to iterate through all of the results into a holding $_post variable.
    public function get_posts_by_user($username) { $bones = new ...

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