Database Reference
In-Depth Information
Listing 8-17. The Signup Controller Route
// create new user & redirect
$app->post('/signup/add', function() use ($app){
$params = $app->request()->post();
// make sure the user name was passed.
$username = trim($params['username']);
//FYI - this is one way to log with SLIM
// $app->log->debug('some message then a variable: ' . $username);
if (!empty($username)) {
// lower case the username.
$username=strtolower($username);
// see if there's already a User node with this username
$checkuser = User::getByUsername($username);
//No? then save it
if(is_null($checkuser)){
// setup the object
$user = new User();
$user->username = $username;
// save it
User::saveUser($user);
// redirect to thank you page
$app->redirect('/thankyou?u='.$username);
}
// show the "try again" message.
else {
$app->view()->setData(array('error' =>
'The username "'.$username.'" already exists. Please try again.'));
$app->render('home/index.mustache');
}
// username field was empty
} else {
$app->view()->setData(array('error' => 'Please enter a username.'));
$app->render('home/index.mustache');
}
});
Adding a User
In each part of the five graph areas covered in the chapter, the domain object will have a corresponding service to
manage the persistence operations within the database. In this case, the User class covers the management of the
application's user nodes using a mix of Neo4jPHP convenience methods and executing Cypher queries.
To save a node and label it as a User, the saveUser method, shown in Listing 8-18, makes use of the Neo4jPHP
save method by passing in the username param and value. Once the node is created, the Neo4jPHP addLabels
method applies the User label.
 
Search WWH ::




Custom Search