Answer the question
In order to leave comments, you need to log in
How to return an error from a controller in Slim 4?
Some rest api is being made.
Authorization by token. We check authorization using middleware
As a result $this->container->get('auth_user')
, we have the current user in the container.
For example, there is such code (there will be many methods):
$app->group('/books', function (Group $group) {
$group->post('/getList', BooksController::class . ':getList')->setName('getList');
$group->post('/getList2', BooksController::class . ':getList2')->setName('getList2');
});
if($this->CheckPermissions($request, $response)){
// действия метода
$response->getBody()->write("List books");
return $response;
}else{
// возврат ошибки доступа
return $this->PermissonsError($request, $response);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question