您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-路由-url生成
发布时间:2022-01-19 22:29:20编辑:雪饮阅读()
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::any('/blog/{id}', [app\controller\Foo::class, 'index'])->name('blog.view');
\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(route('blog.view', ['id' => 100]));
}
public function index2(Request $request)
{
return response('foo index2');
}
public function edit2(Request $request)
{
return response('foo edit2');
}
public function view2(Request $request)
{
return response('foo view2');
}
}
实例请求:
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/1 --dump
/blog/100
注意:
暂时不支持group嵌套的路由生成url
关键字词:webman,url,生成,路由