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 — creating a document with Sag

Now that we have Sag available and ready to use anywhere in our application, let's refactor the saving of the user class that we placed in the /signup post route.

Open index.php, and remove all of the extra code that we added in previous sections so that our /signup post route looks similar to the following code snippet:

post('/signup', function($app) {
$user = new stdClass;
$user->name = $app->form('name');
$user->email = $app->form('email');
$app->couch->post($user);

$app->set('message', 'Thanks for Signing Up ' . $app->form('name') . '!');
$app->render('home');
});

What just happened?

We used Sag to create a post to our CouchDB database using substantially less code! Sag's post method allows you ...

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