1
슬림 한 2 개 프로젝트를 슬림형 3으로 변환하려고합니다. 문제가 있습니다.Slim 2에서 Slim 3으로 방법 오류가 발생했습니다.
내 메서드를 호출 :
Catchable fatal error: Argument 1 passed to authenticate() must
be an instance of Slim\Route, instance of
Slim\Http\Request given in
C:\wamp64\www\task_manager\v1\index.php on line 42.
내가 그것을 어떻게 고칠 수 :
http://localhost:8000/task_manager/v1/tasks
내가 다음 오류가? 어떤 도움을 주시면 감사하겠습니다.
이 Slim2에서$app = new \Slim\App();
...
...
function authenticate(\Slim\Route $route) {
// Getting request headers
$headers = apache_request_headers();
$data = array();
$app = AppContainer::getInstance();
// Verifying Authorization Header
if (isset($headers['Authorization'])) {
$db = new DbHandler();
// get the api key
$api_key = $headers['Authorization'];
// validating api key
if (!$db->isValidApiKey($api_key)) {
// api key is not present in users table
$data["error"] = true;
$data["message"] = "Access Denied. Invalid Api key";
return echoRespnse(401, $data, $response);
//$app->stop();
return $response->withStatus(401)->withBody("Bad Request");
} else {
global $user_id;
// get user primary key id
$user_id = $db->getUserId($api_key);
}
} else {
// api key is missing in header
$data["error"] = true;
$data["message"] = "Api key is misssing";
return echoRespnse(400, $data, $response);
}
}
$app->get('/tasks', function (Request $request, Response $response) {
global $user_id;
$data = array();
$db = new DbHandler();
// fetching all user tasks
$result = $db->getAllUserTasks($user_id);
$data["error"] = false;
$data["tasks"] = array();
// looping through result and preparing tasks array
while ($task = $result->fetch_assoc()) {
$tmp = array();
$tmp["id"] = $task["id"];
$tmp["task"] = $task["task"];
$tmp["status"] = $task["status"];
$tmp["createdAt"] = $task["created_at"];
array_push($data["tasks"], $tmp);
}
return echoRespnse(200, $data, $response);
})->add('authenticate');
당신은() 어디서나'인증 할에'$의 route'를 사용하지 않는 때문에이'기능, 단지'인증합니다 변경 (\ Slim \ Route $ route)'를'authenticate (Request $ request, Response $ response)'로 설정합니다. –
위의 작업을 수행 한 경우,'apache_request_headers()'를 제거하고 Slim의 Request 클래스를 사용하여 대신 가져올 수 있습니다 : https://www.slimframework.com/docs/objects/request.html –
감사합니다. 나는 네가 확신한다고 생각한다. 내 문제를 해결할 수있는 옵션입니다. –