Questions tagged [slim-3]

Slim 3 is the successor to Slim 2, a micro framework for PHP.

Resources

Related tags


For the Ruby template engine use instead.

414 questions
5
votes
2 answers

Slim 3 - Slash as a part of route parameter

I need to compose URLs with parameters that can contain a slash /. For example, the classic /hello/{username} route. By default, /hello/Fabien will match this route but not /hello/Fabien/Kris. I would to ask you how can I do it in Slim 3 framework.
User
  • 194
  • 1
  • 2
  • 15
5
votes
1 answer

Slim3 optional parameter with controller method as callback

I have route: $app->get('/admin/login/{status}', 'App\Controller\Admin\AdminController:loginAction') How do I make {status} parameter optional?
Michal
  • 4,323
  • 5
  • 27
  • 52
5
votes
2 answers

Slim 3 - How to add 404 Template?

In Slim 2, I can over write the default 404 page easily, // @ref: http://help.slimframework.com/discussions/problems/4400-templatespath-doesnt-change $app->notFound(function () use ($app) { $view = $app->view(); …
laukok
  • 47,545
  • 146
  • 388
  • 689
4
votes
1 answer

Slim Controller Request, response and args not available

What I need is : Use a custom class to receive a HTTP Request and deal with it. What I have so far: $app->group('/user', function () use ($app) { $app->post('/login', Auth::class . ':login'); } And in my Auth Class: use…
reinaldomoreira
  • 3,568
  • 2
  • 12
  • 27
4
votes
1 answer

Redirecting to another page on error with Slim Framework

I want to redirect to a page (error.php, for example) depending on the info in a form in my website. I managed to log an error like this: if ($date > $curdate) { return $response ->withStatus(406) ->withHeader('Content-Type',…
Newwt
  • 431
  • 1
  • 4
  • 21
4
votes
4 answers

Slim 3 getParsedBody() always null and empty

I'm am using the Slim Framework Version 3 and have some problems. $app-> post('/', function($request, $response){ $parsedBody = $request->getParsedBody()['email']; var_dump($parsedBody); }); result is always: null Can you help me ?
animatorist
  • 53
  • 1
  • 2
  • 6
4
votes
1 answer

Slim3/DRY - How to handle errors/exceptions correctly without duplicating code?

I'm working on a fairly large JSON API using Slim3. My controllers/actions are currently littered with the following: return $response->withJson([ 'status' => 'error', 'data' => null, 'message' => 'Username or password was…
BugHunterUK
  • 6,765
  • 7
  • 41
  • 94
4
votes
2 answers

Slim Framework 3 - How to inject $logger to route controller

I am using Slim Framework 3. I want to inject $logger defined in dependencies.php into a Router Controller class. Below is what I do, is there a better way? routes.php $app->get('/test', function($request, $response, $args){ $controller = new…
Edison
  • 85
  • 1
  • 5
4
votes
1 answer

JWT: Authentication in slim v3 and Android

I am using Slim framework to return JSON to my Android device. I am currently working on login on my device. I am using 3 different ways to login: Facebook, Google and account login. When he takes account login he can register a new account or login…
kevingoos
  • 2,771
  • 3
  • 30
  • 53
4
votes
5 answers

PHP Slim Framework Create Controller

I am creating an API using the Slim framework. Currently I use a single file to create the route and pass a closure to it: $app->get('/', function($req, $resp){ //Code... }) But I realise that my file has grown rapidly. What I want to do is use…
James Okpe George
  • 3,047
  • 7
  • 42
  • 76
3
votes
2 answers

Slim Respect Validation issue

Respect\Validation\Validator. I have a validator class validator.php
Saurabh Sharma
  • 337
  • 1
  • 3
  • 13
3
votes
2 answers

Exclude route from Slim CSRF middleware

I'm working on a Slim 3 based application with a Twig frontend and I'm also making a REST API. I've implemented slimphp\Slim-Csrf for the entire app but I now want to exclude this CSRF check from every "API" routes. I'm trying to implement the…
joedu12
  • 33
  • 1
  • 4
3
votes
2 answers

Run a function after returning response

I have an API created with Slim 3. In it I have some curl execution such as sending Push notification to a user. I want send response to requester then execute curl or any other function. I read about Threads in PHP and use pthreads-polyfill but it…
3
votes
1 answer

Slim3 - Argument 1 passed to constructor must be instance of Slim\Views\Twig

I'm using Slim3, but I'm having an issue registering a dependency. According to the error the constructor I created expects the type of argument 1 to be Slim\Views\Twig. The problem is I am passing an instance of Slim\Views\Twig - at least I think I…
BugHunterUK
  • 6,765
  • 7
  • 41
  • 94
3
votes
2 answers

Redirecting with error on Slim Framework

I want to redirect to a page (error.php, or maybe 404/406.php, whatever the error is) depending on the info in a form in my website. I managed to log an error like this: if ($date > $curdate) { return $response ->withStatus(406) …
Newwt
  • 431
  • 1
  • 4
  • 21
1
2
3
27 28