福州網(wǎng)站建設(shè)>網(wǎng)站新聞>thinkphp6專區(qū)

        tp6路由中間件無效

        發(fā)布日期:2022-11-20瀏覽次數(shù):461 來源:福州網(wǎng)站建設(shè) 標(biāo)簽: ThinkPHP6 中間件 失效 無效 無奈

        剛試了下最新版TP6,真的不行,大家?guī)涂聪履睦锍隽藛栴}

        開啟多應(yīng)用模式后。

        路由代碼:<?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。

        唉!

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

        網(wǎng)友評(píng)論

        • cyxjq 11月14日

          新版問題多多 越升級(jí)越不好用了

        • XXing 2019年10月13日

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

        thinkphp6專區(qū)有關(guān)的文章
        與標(biāo)簽 ThinkPHP6 中間件 失效 無效 無奈 有關(guān)的文章
        如果您有什么問題,歡迎咨詢我們客服! 點(diǎn)擊QQ咨詢