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');
});
We used Sag to create a post to our CouchDB database using substantially less code! Sag's post method allows you to pass data with it, so it's really easy to trigger.
Let's quickly go through the signup process again:
1. Open up your browser to
http://localhost/verge/signup
.2. Enter in a new name into the Name textbox and a new e-mail...