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

Array after array_unique function is returned as an object in JSON response

im trying to merge two arrays with omitting duplicated values and return it as a JSON with Slim framework. I do following code, but in result I get unique property of a JSON as object - not as an array. I don't know why does it happen, and I'd like…
akn
  • 3,712
  • 26
  • 43
12
votes
2 answers

Slim Framework endpoint unit testing

I'm trying to write some PHPUnit tests for my small slim framework app, but don't see anywhere in the docs that point to a way to do a full request and assert on the response (either containing text or a 200 status, or anything, really). Is there…
tbthorpe
  • 773
  • 1
  • 6
  • 12
12
votes
4 answers

API Client Secret with REST Using Slim Framework

I have a simple REST API (using the Slim framework) set up where the user can call a page like this: subdomain.domain.com/api/musician/id/3273 to retrieve and display some simple JSON data. I want to add some authentication to this so that only…
user1427661
  • 11,158
  • 28
  • 90
  • 132
12
votes
3 answers

How to retrieve POST data from PhoneGaps File Transfer API

I'm using Phone Gaps (Cordova 2.1) file transfer API to post an image from the users photo library to my server. The file transfer API seems to be working fine. I'm just puzzled about retrieving this information on my server. Ideally, what I need to…
Danny
  • 993
  • 4
  • 20
  • 39
12
votes
3 answers

Multiple routes with the same anonymous callback using Slim Framework

How can I define multiple routes that use the same anonymous callback? $app->get('/first_route',function() { //Do stuff }); $app->get('/second_route',function() { //Do same stuff }); I know I can use a reference to a function which would…
Francisc
  • 77,430
  • 63
  • 180
  • 276
11
votes
6 answers

Slim 3 get current route in middleware

I want to get the name of the current I route in a middleware class. Previously (in Slim 2.*) you could fetch the current route like so: $route = $this->app->router->getCurrentRoute(); But this function has been removed in the 3.0 version of Slim.…
Wessel van der Linden
  • 2,592
  • 2
  • 21
  • 42
11
votes
1 answer

Class 'Slim\Slim' not found with composer

I want to use Slim 3 in a subdirectory, but cannot seem to load it. All files are contained in the subdirectory, including composer.json. Here is my composer.json: "require": { "slim/slim": "3.0.0-RC1" } Here is my script:
Kelly Keller-Heikkila
  • 2,544
  • 6
  • 23
  • 35
11
votes
5 answers

Access app in class in Slim Framework 3

Im having trouble understanding how to access the instance of Slim when a route is in a seperate class than index.php When using Slim Framework 2 I always used the following, but its not working in Slim 3: $this->app = \Slim\Slim::getInstance(); Im…
user3507740
  • 113
  • 1
  • 1
  • 5
10
votes
5 answers

Slim\Exception\HttpNotFoundException

I'm creating a new Slim project and getting the following error: Slim Application Error: The application could not run because of the following error: Error Details Type: Slim\Exception\HttpNotFoundException Code: 404 Message: Not found. File:…
Prosenjith Roy
  • 179
  • 1
  • 1
  • 9
10
votes
2 answers

Slim - modify POST request body inside middleware

I am using Slim v3 and the json schema validator by justinrainbow for my API. What I want to do and just can't get to work is: in the middleware: validate incoming json with defaults. this produces a modified object write the modified object back…
tscherg
  • 1,032
  • 8
  • 22
10
votes
5 answers

Why my StringRequest is going always at onErrorResponse method?

I am trying to do a POST request from Android to insert some information in my phpmyadmin. What I am using Slim to make the connection and the query with the database stored at phpmyadmin. XAMPP to simulate a local server. Volley to consume the…
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
10
votes
2 answers

composer phpunit psr-4 autoload class not found

I am giving composer autoload a try with some phpunit testing classes, and I can't seem to get it to work. When I run phpunit from the command line, I get the following error : "PHP Fatal Error: Class ... not found". I will give all the structure…
Finglish
  • 9,692
  • 14
  • 70
  • 114
10
votes
4 answers

Slim controller issue : must be an instance of ContainerInterface, instance of Slim\\Container given

I am trying to use controller in Slim however keep getting the error PHP Catchable fatal error: Argument 1 passed to TopPageController::__construct() must be an instance of ContainerInterface, instance of Slim\Container given My…
lost111in
  • 207
  • 1
  • 3
  • 12
10
votes
1 answer

Controller unit test in slim3

At the outset, I would like to say - I'm new in unit testing in PHP (phpunit). In my new project (slim3 framework) I would like to test my controllers for example LoginController. My idea is (in unit test method) Create instance of…
robertw
  • 724
  • 7
  • 20
10
votes
1 answer

Angularjs and slim framework JWT authentication and token refresh flow

I would like to know if what I've done so far is a sound way of authenticating/renewing the token and if there are any flaws or vulnerabilities that I should be aware of as I tried to limit database interaction to nil. Here goes. The user…
Răzvan
  • 981
  • 9
  • 20