【问题标题】:How to add middileware to slim 2如何将中间件添加到 slim 2
【发布时间】:2021-09-03 04:52:41
【问题描述】:

感谢您阅读我的问题,

我正在尝试向 slim 框架添加中间件,但遇到错误

未捕获的 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();

【问题讨论】:

标签: php slim-2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 2016-01-08
    • 2013-04-06
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多