php - How to add middileware to slim 2

one text

Solution:

i think you should use a clousure as the documentation states;

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

Source