$content = request()->filter('trim', 'strip_tags')->input('content'); if (empty($title)) { $error = '标题不能为空'; } elseif (empty($content)) { $error = '内容不能为空'; } else { (new \Model\Post())->update($pid, $title, $content); response()->redirect(url_base() . '/post/' . $pid); } } return view('post-edit.php', ['post' => $post, 'error' => $error]); })->conditions(['pid' => '[0-9]+'])->name('post-edit'); }, function () { // 路由分组的过滤 if (empty($_SESSION['uid'])) { response()->redirect(url_base() . '/login'); } }); // 路由参数 $app->get('/post/<pid>', function () { $pid = request()->filter('intval')->params('pid'); $post = (new \Model\Post())->get($pid); if (!$post) { throw new \Lime\Exception\NotFoundException("Post not found"); } return view('content.php', ['post' => $post]); })->conditions(['pid' => '[0-9]+'])->name('post-page'); // 使用条件限制数组 和 路由命名 // 执行 Lime 应用 $app->run();