您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-路由-路由分组
发布时间:2022-01-19 22:33:11编辑:雪饮阅读()
路由配置于config/route.php:
有时候路由包含了大量相同的前缀,这时候我们可以用路由分组来简化定义。
实例:
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Webman\Route;
Route::group('/blog', function () {
Route::any('/create', function ($rquest) {
return response('blog create');
});
Route::any('/edit', function ($rquest) {
return response('blog edit');
});
Route::any('/view/{id}', function ($rquest, $id) {
return response("blog view $id");
});
});
实例被请求;
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/create --dump
blog create
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/edit --dump
blog edit
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/view/1 --dump
blog view 1
关键字词:webman,路由,分组