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
8
votes
1 answer

Route Middleware in Slim 4 doesn't stop invoking the callable in the route

I'm strugling with authorization middleware in Slim4. Here's my code: $app = AppFactory::create(); $app->add(new Authentication()); $app->group('/providers', function(RouteCollectorProxy $group){ $group->get('/',…
mk_coder
  • 83
  • 1
  • 5
8
votes
3 answers

how to add twig-view in slimframework v4

I'm trying to add twig-view in slim v4 In slim v3, we add twig-view in container $container['view'] = function ($c) { $view = new \Slim\Views\Twig('path/to/templates', [ 'cache' => 'path/to/cache' ]); // Instantiate and add…
mk990
  • 103
  • 1
  • 1
  • 9
6
votes
1 answer

Accessing route parameters in middleware in Slim 4

I would like to know how I can access route parameter in a middleware in Slim 4. Provided I define a route with placeholder and attached middleware: get('/{userId}', Controller::class) ->add(Middleware::class); I…
Georgy Ivanov
  • 1,573
  • 1
  • 17
  • 24
5
votes
1 answer

Replacement for notFoundHandler setting

I'm migrating from Slim/3 to Slim/4. I've found or figured out replacements for all the features I was using that have been removed, except 404 Not Found Handler (part of the now gone App::$settings): Slim App::$settings have been removed, multiple…
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
4
votes
1 answer

How to use doctrine with slim framework 4?

Trying to use doctrine with slim framework 4, but there is no documentation available. By following information on the link http://www.slimframework.com/docs/v3/cookbook/database-doctrine.html gives error. Class 'slim container' not…
Lovepreet Singh
  • 4,792
  • 1
  • 18
  • 36
4
votes
2 answers

How to set up and inject multiple PDO database connections in slim 4?

I could make an instance of PDO and inject it successfully. I defined the PDO::class directly and injected it in the constructor with __construct(PDO $pdo). I would need something like PDO1::class and PDO2::class to inject it like follows:…
Samuel Gfeller
  • 840
  • 9
  • 19
3
votes
1 answer

PHP Slim 4 getting Request (Psr\Http\Message\RequestInterface) everywhere

I find useful to access to the app settings everywhere in the code. So I put in the container // array passed to DI\ContainerBuilder−>addDefinition() return [ ... 'settings' => function () { return require __DIR__ . '/settings.php'; }, …
simedia
  • 213
  • 2
  • 7
3
votes
1 answer

Slim 4 PUT and DELETE form submissions

How do I do PUT and DELETE form submissions in Slim 4? I have the following route: $group->get('/sites/create', SitesController::class . ':create')->setName('sites_create'); $group->get('/sites/{id}/edit', SitesController::class .…
Martyn
  • 6,031
  • 12
  • 55
  • 121
3
votes
1 answer

How to access slim4's routeParser with the PHP-DI setup demonstrated in Slim-Skeleton?

I've set up a new app based on the SlimPHP team's Slim Skeleton application. Inside of my route definitions, I want to be able to access the route parser as described in the Slim4 documentation. So, for example, I'd like to be able to edit the…
davidreedernst
  • 485
  • 6
  • 11
3
votes
4 answers

How to do a redirect from a Slim 4 middleware?

I've been testing the new Slim 4 framework and redirects work fine for me in normal classes, but I cannot seem to get them working in middleware, where a response is dynamically generated (apparently?) by the Request Handler. When I try to redirect…
ConleeC
  • 337
  • 6
  • 13
3
votes
2 answers

Slim Skeleton returns 404 Not Found

I've installed Slim4 via composer by following the installation guide command, php composer.phar create-project slim/slim-skeleton slimexample Then went to localhost:8080 which returned a json object as below. { "statusCode": 404, "error": { …
amachree tamunoemi
  • 817
  • 2
  • 16
  • 33
2
votes
1 answer

Default route / notFound Error Handling / HttpNotFoundException in Slim 4 PHP

I want to create a Slim 4 compatible custom error page /JSON reply that is returned, when a non-existing route is request. Default route (Slim 3) I've recently upgraded from Slim 3 to Slim 4. With Slim 3, I had a default route that perfectly did the…
BogisW
  • 401
  • 2
  • 16
2
votes
1 answer

In Fedora 31 how do I set permissions for nginx running in a Podman container?

I am trying to set up a local dev LEMP stack for a Slim-4 project using podman-compose. So far I have containers for PHP and Nginx. Nginx runs but gives a 500 error on trying to access the log directory - permission denied. This directory is outside…
Roger Creasy
  • 1,419
  • 2
  • 19
  • 35
2
votes
1 answer

PHPUnit test specific method of class with dependencies

After reading quite some docs I came up with this function to test the service method findAllUsers. I first create a stub of the repository, then tell what the relevant method findAllusers returns (yes they have the same name in repo and service)…
Samuel Gfeller
  • 840
  • 9
  • 19
2
votes
2 answers

Slim 4 get all routes into a controller without $app

I need to get all registed routes to work with into a controller. In slim 3 it was possible to get the router with $router = $container->get('router'); $routes = $router->getRoutes(); With $app it is easy $routes =…
harley81
  • 190
  • 2
  • 12
1
2 3 4 5 6 7