route()生成url没有成功映射路由的[可选]规则

lirko

问题描述

http://webman.com/123/webman
期待结果 /123/webman

http://webman.com/123
期待结果 /123
实际结果 /123/{name}

程序代码或配置

class Index extends Base
{
    public function index($id,$name='web')
    {
        return view('index/index',['data'=>['id'=>$id, 'name'=>$name,]]);
    }
Route::get('/{id}[/{name}]', [app\controller\Index::class, 'index'])->name('index/index');
index/index.html
{:route('index/index', ['id' => $data.id,'name' => $data.name])}
{:route('index/index', ['id' => $data.id])}
http://webman.com/123/webman
实际生成 /123/webman

http://webman.com/123
实际生成 /123/{name}    //这不是我希望的结果

操作系统环境及workerman/webman等具体版本

Deban12 php8.4.8
"require": {
"php": ">=8.1",
"workerman/webman-framework": "^2.1",
"monolog/monolog": "^2.0",
"webman/think-orm": "^2.1",
"topthink/think-template": "^3.0",
"webman/redis": "^2.1",
"illuminate/events": "^12.37"
},

138 1 0
1个回答

10bang

两条规则都写上

  • 暂无评论
🔝