Slim 4 is an open source PHP micro framework that helps writing web applications and APIs.
Questions tagged [slim-4]
93 questions
2
votes
1 answer
How to getAttribute from middleware in slim
I have a problem when I try to get an attribute set in a previous middleware in Slim 4.
I use middlewares in app/middleware.php
I use JwtAuthentication middleware to check a token and I want to pass the decoded token to the next middleware :…

Patrice Flao
- 491
- 5
- 18
2
votes
1 answer
ThePHPLeague OAuth2 Client `getAccessToken()` throws "An OAuth server error was encountered that did not contain a JSON body" error
I have been attempting to develop an API and client which communicate to each other via an implementation of ThePHPLeague's OAuth2 server and client. Using the curl command in a CLI, I am able to generate a token and use it to gain access to…

Muckee
- 474
- 1
- 8
- 26
1
vote
1 answer
How to pass a param in Slim4 route middleware?
I'm using Slim4 and I need to pass a param in middleware route configurations.
In my example I need to define the required ROLE of user in a Authorization middleware.
I need to check that user is a manager in the first route group, and an admin in…

Tobia
- 9,165
- 28
- 114
- 219
1
vote
0 answers
Automatically generate/call new jwt token if token expires php slim 4
I really appreciate it if someone can help me here. Is there a way I can call the endpoint that generates the api jwt token within my container, anytime the last one expires? below is auth part of my container
App::class => function…

chized
- 23
- 1
- 6
1
vote
1 answer
How to implement this Slim 3 middleware to Slim 4 middleware
I have this code from my Slim-3 middleware, how can I convert this to Slim-4 middleware. It seem in slim4, we need to return some response instead return the callable $next
//route middleware
$app->add(function (Request $request, Response $response,…

jumper rbk
- 414
- 4
- 18
1
vote
0 answers
Slim Framework 4: process request manually
I'm developing Web API with Slim Framework 4. Nothing special, everything as usual. Request handlers are something like:
$app = \Slim\Factory\AppFactory::create();
...
$app->get('/resource', function($request, $response)
{
…

nyan-cat
- 610
- 5
- 19
1
vote
1 answer
How to connect angular10 post api with slim 4 php?
My angular application runs on http://localhost:4200/ and my Slim4 application runs on localhost:8080. When I try to integrate APIS between angular and slim, GET API works fine, but the POST API does not. I get the below CORS error,
Access to…

prisel
- 337
- 2
- 14
1
vote
1 answer
Get settings in slim 4 (eg. path of application root directory)
Question
How can I access the path settings, or more general, how do I access settings defined in the settings.php.
My settings.php
Important note: These are the values for the test environment, they have to be changed for production!
// Should be…

BogisW
- 401
- 2
- 16
1
vote
1 answer
Add value to route before in slim framework
Hi Folks i upgrading my slim framework from slim 2 to slim 4 for older project
for one route i added the one value before route using slim 2 slim.before in index.php
example code:
$app->hook('slim.before', function () use ($app) {
$env =…

Dinesh s
- 313
- 4
- 19
1
vote
1 answer
Is there a way to allow CORS to process custom headers on preflight response
I'm using slim framework v4 for building API. I discovered that using custom headers doesn't work at all. I will appreciate any lead on resolving this issue.
I have followed the documentation on…

Olotin Temitope
- 419
- 6
- 13
1
vote
1 answer
Slim 4 catching php warnings, notices & errors
I just started using the slim framework and want to catch php warnings, notices and errors with a custom error handler.
ErrorHandlerMiddleware.php

Grobanix
- 139
- 1
- 3
- 12
1
vote
0 answers
Slim4 through openapi-generator deployment problems
I've been working on this for several days now and I'm at the point of pulling my hair out.
Goal: to deploy Slim4 on my LAMP server within a specific subdirectory and accessible via a simple URL.
Structure:
There are several instances of my web app…

eestikul
- 11
- 1
1
vote
1 answer
Slim 4 throws Slim\Exception\HttpNotFoundException
I am having this error
I have been the whole day looking for solutions, including trying to set the proper directories as said here, also including the two .htaccess files required, but nothing…
user6791921
1
vote
1 answer
Slim Framework 4 getParsedBody Always returns null
I'm testing Slim Framework 4 and I can't seem to be able to retrieve any data when I'm submiting a JSON via POST, using the getParsedBody method, it always results in NULL. Here is my endpoint:

Rainier Araujo
- 31
- 2
1
vote
1 answer
Respect\Validation with slim4
I'm trying to follow this tutorial for add post params validation: https://odan.github.io/2020/10/08/slim4-respect-validation.html
I add a lib, and use it:
private function validateProperty(array $data): void
{
$validator = new v();
…

Phyron
- 613
- 1
- 9
- 25