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 — making a function to handle Post creation

Let's create a public function called create that will handle the creation of posts for our application.

  1. Open classes/post.php, and scroll to the bottom. Here, we'll create a new public function called create.
    public function create() {
    }
    
  2. Let's start by getting a new instance of Bones, and then setting the variables of the current post object.
    public function create() {
    $bones = new Bones();
    $this->_id = $bones->couch->generateIDs(1)->body->uuids[0];
    $this->date_created = date('r');
    $this->user = User::current_user();
    }
    
    
  3. Finally, let's put the document to CouchDB, using Sag.
    public function create() { $bones = new Bones(); $this->_id = $bones->couch->generateIDs(1)->body->uuids[0]; $this->date_created ...

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