スリムフレームワークv2で認証用のミドルウェアを作成しました。 http://docs.slimframework.com/routing/middleware/#what-arguments-are-passed-into-each-route-middleware-callableスリムv2未定義変数
$app->get('/cases/shared/group/:group_id', 'authenticate', $authenticate2($app->router()->getCurrentRoute(), 'member', 'group'), function ($group_id) use ($app) {
$limit = $app->request()->params('limit');
$offset = $app->request()->params('offset');
$search = $app->request()->params('search');
$order = $app->request()->params('order');
$objCases = new Cases();
$result = $objCases->getSharedWithGroupCases($group_id, $limit, $offset, $search, $order);
if ($result === null) {
$response["error"] = true;
$response["message"] = _("İlgili grup ile paylaşılan olgu bulunmamaktadır.");
} else {
$response["error"] = false;
$response["data"] = $result;
$response["total_data"] = $objCases->getNumOfSharedWithGroupCasesData($group_id, $search, $order);
}
echoResponse(200, $response);
});
認証]:ここで
はチュートリアルです。 :
function authenticate(\Slim\Route $route) {
$headers = getallheaders();
$response = array();
$app = \Slim\Slim::getInstance();
if (isset($headers['Authorization'])) {
if(strpos($headers['Authorization'], '.') !== false) {
$authorization = explode('.', $headers['Authorization']);
$api_key = $authorization[0];
$user_id = $authorization[1];
$objUsers = new Users();
if ($objUsers->isValidUser($user_id, $api_key) <= 0) {
$response["error"] = true;
$response["message"] = "Access Denied. Invalid Api key";
echoResponse(401, $response);
$app->stop();
}
} else {
$response["error"] = true;
$response["message"] = "Access Denied. Invalid Api key";
echoResponse(401, $response);
$app->stop();
}
} else {
$response["error"] = true;
$response["message"] = "Api key is misssing";
echoResponse(400, $response);
$app->stop();
}
}
$authenticate2 = function (\Slim\Route $route, $role, $where) {
$response["group_id"] = $route->getParam('group_id');
$response["role"] = $role;
$response["where"] = $where;
echoResponse(200, $response);
};
最初の認証方法がうまくいきます。私は送ることができますどのように$app->get('/cases/shared/group/:group_id', 'authenticate', $authenticate2($app->router()->getCurrentRoute(), 'member', 'group'), function ($group_id) use ($app) {
:中authenticate2
関数名は文字列でなければなりません
エラーライン:
未定義の変数:しかし、第二の認証方法は、2つのエラーを返します。経路とパラメータをミドルウェアに統合する