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 our application to consume the reduce function

Now that we have created the reduce function, let's add some code to our application to retrieve the value.

  1. Open classes/post.php.
  2. Now that we've created a reduce function, we need to make sure that the get_posts_by_user function uses the view without using the reduce function. We'll do this by adding reduce=false to the query string. This tells the view not to run the reduce function.
    public function get_posts_by_user($username) {
    $bones = new Bones();
    $posts = array();
    foreach ($bones->couch- >get('_design/application/_view/posts_by_user?key="' . $username . '"&descending=true&reduce=false')->body->rows as $_post) {
    
    
  3. Create a new public function called get_post_count_by_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