Questions tagged [slim]

Slim for PHP is a RESTful micro framework for PHP 5 inspired by Sinatra.

  • Slim 3 requires PHP 5.5.0 or newer.

Resources

Features

  • Router Slim uses the FastRoute router and maps route callbacks to specific HTTP request methods and URIs. It supports route segment parameters and pattern matching.

  • Middleware Build your application with custom concentric middleware to tweak the HTTP request and response objects before and after your Slim app runs.

  • HTTP Slim has easy-to-use PSR-7 request and response abstractions that let you inspect and manipulate HTTP messages' method, status, URI, headers, cookies, and body.

Related tags


For the Ruby template engine use instead.

2828 questions
7
votes
2 answers

Slim : how to log all request to the framework

I would like to log all requests to my Slim Rest server. 200 ok, 404 errors, etc... With the following code I can only log Exceptions. I want to log all the incoming requests. require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); require…
user3149715
  • 139
  • 1
  • 2
  • 4
7
votes
2 answers

hooks versus middleware in slim 2.0

Can anyone explain if there are any significant advantages or disadvantages when choosing to implement features such as authentication or caching etc using hooks as opposed to using middleware? For instance - I can implement a translation feature by…
Antony Castle
  • 193
  • 1
  • 11
7
votes
4 answers

Newrelic isn't recognizing my Slim PHP routes

I have just set up New Relic on my PHP web app. Everything is working great except one thing... All of the transactions show as going through "index.php". The reason for this because I'm using the Slim framework (there are many alternatives for…
Brian
  • 541
  • 3
  • 15
7
votes
5 answers

Slim PHP returning JSON

So basically I have my backbone application making an ajax GET call to my slim php app. It expects JSON dataType in return. $.ajax({ url: './myroute', type: 'GET', dataType: "json", data: { username: username,…
Devin
  • 737
  • 2
  • 8
  • 14
7
votes
4 answers

Always get 404 error in Slim Framework when omitting index.php in URL

I created a test hello world Slim app following instructions here. When I make this call I get a 404 error: http://my_server/my_app/hello/John In the other hand, when I make this call it works grand as I get a "Hello John"…
German Latorre
  • 10,058
  • 14
  • 48
  • 59
7
votes
3 answers

How do I get Slim Framework to work without having to put /index.php in the URL?

I am implementing Slim Framework for PHP and everything appears to be working just fine. However, the only way I can get it to work is by putting /index.php in the URL like this: http://www.example.com/index.php/members/1 I want it to work like…
Progger
  • 2,266
  • 4
  • 27
  • 51
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
6
votes
1 answer

Slim framework : upgrade from version 3 to version 4?

I've a slimframework v3 application that provide REST API for an Angular application. I want to upgrade to v4, but there's quite a lot of changes and the upgrade page, while it mention what is changing, it's pretty dry on how to make those change…
Thomas
  • 1,231
  • 14
  • 25
6
votes
2 answers

PHP, PDO SQL server, the leading 0 number is cut from the return data

I'm working on PHP + Slim Framework. I have to migrate MySQL to SQL Server. There is something wrong with the return result from SELECT statement. Here is my example data, ╔════╦═══════╦════════════╦════════════╦═══════════════════════╗ ║ id…
Hikaru Shindo
  • 2,611
  • 8
  • 34
  • 59
6
votes
3 answers

Slim Callable UserController does not exist RuntimeException

Hi i am new to slim i stuck on this anyone help please routes.php $app->get('/', 'UserController:index'); dependencis.php $container['src\UserController'] = function ($container) { return new…
Shahzad Nasir
  • 168
  • 1
  • 2
  • 11
6
votes
3 answers

Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable

I'm using Eloquent in combination with Slim Framework to build a small API. For some reason, I am getting this error, and I can't locate the problem: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. Database settings are…
wout
  • 2,477
  • 2
  • 21
  • 32
6
votes
1 answer

Mock Slim endpoint POST requests with PHPUnit

I want to test the endpoints of my Slim application with PHPUnit. I'm struggling to mock POST requests, as the request body is always empty. I've tried the approach as described here: Slim Framework endpoint unit testing. (adding the environment…
Florian Moser
  • 2,583
  • 1
  • 30
  • 40
6
votes
4 answers

How to access all routes from Slim 3 php framework?

I am trying to build a dynamic drop-down menu from routes defined in Slim framework and here is my question - is there a way to access all defined static routes from some kind of array? For instance, if I define my routes like this: // Index page:…
Vladimir Jovanović
  • 3,288
  • 1
  • 20
  • 27
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
6
votes
3 answers

Monolog RotatingFileHandler save to a specific file according to log type

I'm trying to do something with monolog that I'm not sure it's possible. So I was thinking of a practical way to organize the log files. First I thought to have 3 different files, INFO, WARNING and ERROR, but it would be difficult to search a…
Carla Sousa
  • 393
  • 4
  • 12