Questions tagged [slim-4]

Slim 4 is an open source PHP micro framework that helps writing web applications and APIs.

Resources

Related tags

93 questions
0
votes
0 answers

Slim router argument issue

Simple code $app->get('/hello/{name}', function (Request $request, Response $response, $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); return $response; }); When I am passing name like…
Niko Jojo
  • 1,204
  • 2
  • 14
  • 31
0
votes
1 answer

Why does a container run before middleware?

If we look at the Middleware concept published on the slim4 website and elsewhere. It should be executed before a request reaches the application or when sending the response to the user. The question is this, because even if a Middleware is…
Jerfeson Guerreiro
  • 745
  • 1
  • 10
  • 19
0
votes
1 answer

Overriding injected class from routing group in Slim 4?

I have a Slim4 Application composed of several modules separated in different routing groups, like so: $app->group('/app', function(RouteCollectorProxy $app) { /*blah blah*/ })->add(MyMiddleWare::class); $app->group('/api',…
Jonathan DS
  • 2,050
  • 5
  • 25
  • 48
0
votes
1 answer

How to set an attribute to route definition in Slim4 and use it in a middleware

I need to set a custom attribute in the route definition and use it a route middleware. For example, I need to manage the refer page to redirect the user after the login. This is my routes definition: return function (App $app) { $app->get('/',…
Tobia
  • 9,165
  • 28
  • 114
  • 219
0
votes
1 answer

How to add common model to Twig and Slim4

I'm using Twig and Slim4 with DI container (the same as this tutorial: https://odan.github.io/2019/11/05/slim4-tutorial.html). I would like to know how can I add a common model to all my twig views, for example user object, general options and…
Tobia
  • 9,165
  • 28
  • 114
  • 219
0
votes
1 answer

Access $app or $request in Eloquent using Slim Framework

I am building a Slim Framework 4 Api Application, with Eloquent. public/index.php $capsule = new \Illuminate\Database\Capsule\Manager; $capsule->addConnection($dbconfig); $capsule->setAsGlobal(); $capsule->bootEloquent(); $app->add(new…
Alaksandar Jesus Gene
  • 6,523
  • 12
  • 52
  • 83
0
votes
1 answer

Slim 4: Use a container to share DB connection with models and controllers without Eloquent

I am starting a PET project with SLIM 4 and I can't find a way to use the connection to the database within a Model. Even the controller works ok. I have used a container to be able to move the connection between the different…
Marc Torres
  • 23
  • 2
  • 4
0
votes
0 answers

Slim 4 middleware redirect *on the way in*

I have the following middleware that I'll attach to my route: class RequireAuth extends Base { public function __invoke(Request $request, RequestHandler $handler): Response { // On my way in, get authenticated user... // I…
Martyn
  • 6,031
  • 12
  • 55
  • 121
0
votes
1 answer

How to create new stream from Redis cache

I am storing image inside redis. $image = $cache->remember($key, null, function () use ($request, $args) { $image = $this->get('image'); $storage = $this->get('storage'); return…
user3485442
0
votes
1 answer

Fatal error: Uncaught TypeError: Argument 1 passed to Slim\Views\Twig

I keep getting Fatal error: Uncaught TypeError: Argument 1 passed to Slim\Views\Twig::__construct() must be an instance of Twig\Loader\LoaderInterface, string given ... Code is: require DIR .'/vendor/autoload.php'; $container = new Container();…
C Besner
  • 11
  • 1
0
votes
1 answer

Slim 4 monolog does not write logs

I configured monolog in my slim 4 application and set logErrors and logErrorDetails to true in ErrorMIddleware but when I got an error it does not write logs. To emulate error I turn on the cache on my app and I'm getting an error like this Call to…
Bogdan Dubyk
  • 4,756
  • 7
  • 30
  • 67
0
votes
1 answer

Slim 4 error handling not catching base Exception

For some reason, my Slim 4 application error handler did not catch errors which can be caught by \Exception and I see 502 bad gateway error in the browser , here is my ErrorMiddleware configuration (I'm using PHP-DI to configure it ): …
Bogdan Dubyk
  • 4,756
  • 7
  • 30
  • 67
0
votes
1 answer

How to inject a service into Behat feature context in Slim 4 framework

When I search for service injection to feature context I always find extensions for symfony. But I need extension or something else to do this in Slim 4 framework. Thank you.
Furkan
  • 415
  • 5
  • 17
0
votes
2 answers

OPTIONS request before GET request with Authorization Header not working in slim framework 4

I have cloned slim skeleton (https://github.com/slimphp/Slim-Skeleton) which already have CORS implemented. But still when API calls OPTIONS before GET, it sends 405 ERROR "Method not allowed. Must be one of: GET" Here is my route where I face this…
Ankur
  • 519
  • 8
  • 15
0
votes
3 answers

Inject container in controller class

I'm migrating my app from Slim/3 to Slim/4. Perhaps I'm confused because there're endless syntaxes for the same stuff but I composed this: use DI\Container; use Slim\Factory\AppFactory; use Slim\Psr7\Request; use Slim\Psr7\Response; require…
Álvaro González
  • 142,137
  • 41
  • 261
  • 360