0

感谢您阅读我的问题,

我正在尝试将中间件添加到苗条框架,但遇到错误

未捕获的 InvalidArgumentException:所有 Route 中间件必须是可调用的

           $authenticateForRole = function ( $user_Id, $tokenKey ) {
                 try {
                     // my stuffs 
                      }
                  } catch (\Throwable $th) {
                      echo $th->getMessage();
                      return false;
                  }
              };


              $app->map('/averageresponsetime/',$authenticateForRole($UserId, $token), function () use ($app) { 
                   echo json_encode($post1);
              })->via('POST');
              $app->run();
4

1 回答 1

2

我认为您应该使用文档所述的clousure;

$authenticateForRole = function ( $user_Id, $tokenKey ) {
    return function () use ( $user_Id, $tokenKey ) {
                 try {
                     // my stuffs 
                      }
                  } catch (\Throwable $th) {
                      echo $th->getMessage();
                      return false;
                  }
        }
};
于 2021-09-03T06:22:47.757 回答