I bet you thought the login script was pretty easy. Wait until you see how easy it is for us to allow users to log out.
1. Open
classes/user.php
, and create apublic static
function calledlogout.
public static function logout() { $bones = new Bones(); $bones->couch->login(null, null); session_start(); session_destroy(); }
2. Add a route into the
index.php
file, and have it call thelogout
function.get('/logout', function($app) { User::logout(); $app->redirect('/'); });
3. Notice that we are calling a new feature inside of Bones
–
aredirect
function. In order for this to work, let's add a quick new function at the bottom of ourpublic function redirect($path = '/') { header('Location: ' . $this->make_route($path)); }