福州網站建設>網站新聞>thinkphp6專區

        tp6路由中間件無效

        發布日期:2022-11-20瀏覽次數:497 來源:福州網站建設 標簽: ThinkPHP6 中間件 失效 無效 無奈

        剛試了下最新版TP6,真的不行,大家幫看下哪里出了問題

        開啟多應用模式后。

        路由代碼:<?php

        use think\facade\Route;

        Route::rule('index', 'index/index')
            ->middleware(\app\community\middleware\User::class)
            ->ext('html');
        中間件代碼:<?php

        namespace app\community\middleware;

        class User
        {
            public function handle($request, \Closure $next)
            {
                $request->test_value = 1;
                return $next($request);
            }
        }
        控制器代碼:<?php

        namespace app\community\controller;

        class Index
        {
            public function index()
            {
                dump(6);
                dump(\request()->test_value);
            }

        }
        然后訪問/index.html輸出6與null。

        唉!

        以上是由福州網站建設的小編為你分享了"tp6路由中間件無效"文章,如果你在這方面有什么問題,隨時聯系我們

        網友評論

        • cyxjq 11月14日

          新版問題多多 越升級越不好用了

        • XXing 2019年10月13日

          你的路由設置成功了嗎?
          為什么我總是找不到路由的?

        thinkphp6專區有關的文章
        與標簽 ThinkPHP6 中間件 失效 無效 無奈 有關的文章
        如果您有什么問題,歡迎咨詢我們客服! 點擊QQ咨詢