public static function setLoggedIn($username) { $key = md5(uniqid()) . md5(uniqid()); DB::getInstance()->update(['blog_session_id' => $key])->table('user')->where('username', '=', $username)->execute(); Slim::getInstance()->setCookie('blog_session_id', $key); $result = DB::getInstance()->select()->from('user')->where('username', '=', $username)->execute()->fetchAll(\PDO::FETCH_OBJ); self::$_isLoggedIn = true; self::$_currentUser = $result[0]; }
$app = new \Slim\Slim(); /** * Step 3: Define the Slim application routes * * Here we define several Slim application routes that respond * to appropriate HTTP request methods. In this example, the second * argument for `Slim::get`, `Slim::post`, `Slim::put`, `Slim::patch`, and `Slim::delete` * is an anonymous function. */ $app->get('/', function () use($app) { $posts = \Slim\DB::getInstance()->select()->from('post')->orderBy('created', 'desc')->execute()->fetchAll(PDO::FETCH_OBJ); $app->view('Slim\\View\\Layout'); $app->render('index.php', ['posts' => $posts]); })->name('home'); $app->get('/post/:id', function ($id) use($app) { $posts = \Slim\DB::getInstance()->select()->from('post')->where('id', '=', $id)->orderBy('created', 'desc')->execute()->fetchAll(PDO::FETCH_OBJ); if ($posts) { $app->view('Slim\\View\\Layout'); $app->render('post.php', ['post' => $posts[0]]); } else { $app->notFound(); } })->name('post'); /* Admin area*/ $app->get('/admin', 'Slim\\Admin:indexAction')->name('admin-home'); $app->get('/admin/new', 'Slim\\Admin:newAction')->name('post-new'); $app->post('/admin/save', 'Slim\\Admin:saveAction')->name('post-save'); $app->post('/admin/login', 'Slim\\Admin::loginAction')->name('login'); $app->get('/admin/edit/:id', 'Slim\\Admin:editAction')->name('post-edit'); $app->get('/admin/delete/:id', 'Slim\\Admin:deleteAction')->name('post-delete'); /* Admin area*/