diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 5924664..e99187b 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -20,7 +20,13 @@ class Article extends BaseController ]; //文章分类 - public function cate(){ + public function cate() + { + //非法请求参数,抛出异常 + if(count(Request::param()) >3){ + // 抛出 HTTP 异常 + throw new \think\exception\HttpException(404, '请求异常'); + } //获取分类ID $ename = Request::param('ename'); diff --git a/app/index/route/route.php b/app/index/route/route.php index cd2ff15..ef4d7d8 100644 --- a/app/index/route/route.php +++ b/app/index/route/route.php @@ -14,7 +14,11 @@ Route::get('captcha/[:config]','\\think\\captcha\\CaptchaController@index'); Route::rule('/', 'index'); // 首页访问路由 Route::group(function () { Route::get('jie/:id', 'article/detail'); - Route::get('column///','article/cate'); + Route::get('column///','article/cate') + ->pattern([ + 'ename' => '\w+', + 'page' => '\d+', + ]); Route::rule('add','article/add'); Route::rule('edit/[:id]','article/edit'); //Route::rule('del/:id','article/delete');