国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

怎么給request()新增自定義的方法

zhuyujin001

問題描述

這里寫問題描述
1、想為\support\Request新增方法isPc()、isCli()、getInfo() ,報(bào)錯(cuò)(如下)
2、還有在allRequest.php新增的方法能不能同步到request()里,怎么操作?
我目前如下配置:
在webman/app/AllRequest.php

class AllRequest  extends \support\Request
{
 public function isPc()
 {
   return  ......
 }

 public function isCli()
 {
   return  ......
 }
 public function getInfo()
 {
   return  ......
 }
 ........
}

在config/app.php

use app\AllRequest as Request;
return [
    'debug' => true,
    'error_reporting' => E_ALL,
    'default_timezone' => 'Asia/Shanghai',
    'request_class' => Request::class,
    'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public',
    'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime',
    'controller_suffix' => 'Controller',
    'controller_reuse' => false,
];

在config/dependence.php

return [
    \app\AppRequest::class => function() {
        return request();
    }
];

以上配置后

在項(xiàng)目根目錄下的common/Uitls.php里使用

public function ...()
{
(new AllRequest)->isPc()
報(bào)錯(cuò):ArgumentCountError: Too few arguments to function Workerman\Protocols\Http\Request::__construct()
}

還有在allRequest.php新增的方法能不能同步到request()里,怎么操作?

829 1 0
1個(gè)回答

walkor 打賞

你為什么要new AllRequest?

(new AllRequest)->isPc()

改成

request()->isPc()
  • zhuyujin001 2024-03-19

    哦 我可能是沒有重啟,開始request()->isPc()是報(bào)不存在此方法,重啟后又沒問題了 感謝啊

  • army 2024-03-21

    這是webman的,workerman的怎么弄?

  • walkor 2024-03-21

    new Worker() 后執(zhí)行 \Workerman\Protocols\Http::requestClass('自定義Request類名');

年代過于久遠(yuǎn),無法發(fā)表回答
??