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 theget_posts_by_user
function uses the view without using thereduce
function. We'll do this by addingreduce=false
to the query string. This tells the view not to run thereduce
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 calledget_post_count_by_user
that will accept$username
as a parameter.public function get_post_count_by_user($username) { }
4. Let's add a call to our view that mimics our
get_posts_by_user
function. But, this time, we'll addreduce...