$app->get('/about', '\\Controller\\About@index'); $app->get('/login', function () { return view('login.php'); })->filter(function () { // 路由过滤 if (!empty($_SESSION['uid'])) { response()->redirect(url_base()); // 跳转 } }); $app->post('/login', function () { $username = request()->filter('trim', 'strip_tags')->input('username'); $password = request()->input('password'); $User = new \Model\User(); // 模型 $uid = $User->login($username, $password); if ($uid) { $_SESSION['uid'] = $uid; response()->redirect(url_base()); } // 视图数据 return view('login.php', ['error' => '用户不存在或者密码不匹配.']); }); $app->get('/logout', function () { $_SESSION['uid'] = ''; unset($_SESSION['uid']); response()->redirect(url_base() . '/login'); }); // 路由分组 $app->group('/post', function () { $this->get('/new', function () {