webman:配置路由(v1.5.7)

发布时间 2023-08-19 09:06:25作者: 刘宏缔的架构森林
 

一,官方文档地址:

https://www.workerman.net/doc/webman/route.html

二,php代码:

config/route.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
 
use Webman\Route;
 
//指定默认页面
Route::get('/', [app\controller\IndexController::class, 'index']);
 
//组路由
Route::group('/image', function () {
    Route::get('/list', [app\controller\ImageController::class,'list']);
    Route::post('/add', [app\controller\ImageController::class,'add']);
});
 
//自定义404的json返回
Route::fallback(function(){
    return json(['code' => 404, 'msg' => '404 not found']);
});
 
//关闭默认路由
Route::disableDefaultRoute();

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/08/18/webman-pei-zhi-lu-you-v1-5-7/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com

三,测试效果:

正常返回:

404:

四,查看webman的版本:

liuhongdi@lhdpc:/data/webman/imageadmin$ composer show workerman/webman-framework
name     : workerman/webman-framework
descrip. : High performance HTTP Service Framework.
keywords : High Performance, http service
versions : * v1.5.7
...