Now that we have access to the _rev
variable in our base
class, let's add support so that our application can delete posts from the user profile.
1. Let's start by opening
classes/post.php
and adding a line of code to theget_posts_by_user
function so that we have_rev
available to us.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) { $post = new Post(); $post->_id = $_post->value->_id; $post->_rev = $_post->value->_rev; $post->date_created = $_post->value->date_created;
2. Next, let's create a nice and simple
delete
function in theclasses/post.php
file, so we can delete the posts.public function delete() { $bones = new Bones(); try { $bones->couch->delete($this->_id, $this->_rev...