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.

421 questions
6
votes
8 answers

Unreasonable Errors on PHP Slim 3 Middleware

I am trying to use the ValidationErrorsMiddleware.php class as a middleware, so I added the following code to my bootstrap/app.php: $app->add(new App\Middleware\ValidationErrorsMiddleware($container)); I got the following errors after the above…
DarkSpirit
  • 307
  • 1
  • 3
  • 6
5
votes
1 answer

Slim 3 - remove subdir from url with rewrite rule

I have a shared hosting on A2Hosting and I recently moved my main domain from public_html/ to public_html/subdir/ Here's the structure: /public_html /subdir(site files of main domain) /api index.php My current htaccess(public_html) is :…
Jean R.
  • 476
  • 4
  • 16
  • 44
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
  • 314
  • 2
  • 3
  • 15
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(); …
Run
  • 54,938
  • 169
  • 450
  • 748
4
votes
1 answer

Composer Fatal error: Cannot redeclare composerRequire

When running the PHP Development server on my MacOS I get the following error from composer. Fatal error: Cannot redeclare composerRequire01a3dc0b1f885ed2b645be37711584c1() (previously declared in…
Xenology
  • 2,357
  • 2
  • 21
  • 39
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
  • 5,388
  • 3
  • 14
  • 29
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
  • 491
  • 1
  • 5
  • 22
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
  • 8,346
  • 16
  • 65
  • 121
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
  • 7
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
  • 3,785
  • 4
  • 36
  • 63
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…
George
  • 3,757
  • 9
  • 51
  • 86
3
votes
2 answers

How to read the response body when API error happen using curl?

I developed an API using Slim v3, when an exception is raised I have an ErrorHandler which return the following: public function __invoke(Request $request, Response $response, \Exception $exception) { $status = $exception->getCode() ? : 500; …
sfarzoso
  • 1,356
  • 2
  • 24
  • 65
3
votes
2 answers

Slim 3 framework - Passing data from middleware to controller - action args

I'm using a controller/middleware build with slim 3 and i want from the middleware attached to a group, to pass some data to the $args parameter in my controller - action. Here's some code: class MyController { protected $container; public…
C Apetrei
  • 35
  • 1
  • 7
3
votes
2 answers

Slim Respect Validation issue

Respect\Validation\Validator. I have a validator class validator.php
Saurabh Sharma
  • 463
  • 2
  • 7
  • 20
3
votes
1 answer

Twig default to text within block if block is empty?

On my template I am using the following to define a og:meta image url, some pages will override this. Now, what I want to do is have a default image there if the block is…
Joe Scotto
  • 10,936
  • 14
  • 66
  • 136
1
2
3
28 29