您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-路由-路由参数
发布时间:2022-01-19 22:31:24编辑:雪饮阅读()
在config/route.php配置如
use Webman\Route;
Route::any('/testclass/{id}', [app\controller\Foo::class, 'index']);
在\app\controller\Foo.php中实现如:
<?php
namespace app\controller;
use support\Request;
class Foo
{
/**
* 该方法会在请求前调用
*/
public function beforeAction(Request $request)
{
echo 'beforeAction';
// 若果想终止执行Action就直接返回Response对象,不想终止则无需return
// return response('终止执行Action');
}
/**
* 该方法会在请求后调用
*/
public function afterAction(Request $request, $response)
{
echo 'afterAction';
// 如果想串改请求结果,可以直接返回一个新的Response对象
// return response('afterAction');
}
public function index(Request $request,$id)
{
return response('hello index id:'.$id);
}
}
然后请求实例:
[root@localhost ~]# elinks http://127.0.0.1:8787/testclass/1 --dump
hello index id:1
关键字词:webman,路由,参数