禁止非法访问文章分类,抛出异常

This commit is contained in:
taoser 2021-03-20 16:32:23 +08:00
parent c6ac0cba25
commit c049c1318e
2 changed files with 12 additions and 2 deletions

View File

@ -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');

View File

@ -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/<ename?>/<type?>/<page?>','article/cate');
Route::get('column/<ename?>/<type?>/<page?>','article/cate')
->pattern([
'ename' => '\w+',
'page' => '\d+',
]);
Route::rule('add','article/add');
Route::rule('edit/[:id]','article/edit');
//Route::rule('del/:id','article/delete');