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
18
votes
3 answers

How to POST backbone model data to DB through Slim php and Paris

I'm trying to get an understanding of how Backbone.js, Slim PHP and Paris/Idiorm might work together and I'm having trouble completing the flow, starting with model attribute data, all the way to the database. PROBLEM: What exactly gets sent to my…
jmk2142
  • 8,581
  • 3
  • 31
  • 47
18
votes
2 answers

How to access the $container within middleware class in Slim v3?

I've been reading that in Slim v2, $app was bound to the middleware class. I'm finding this not to be the case in v3? Below is my middleware class, but I'm just getting undefined:
Martyn
  • 6,031
  • 12
  • 55
  • 121
18
votes
1 answer

Securing a REST API and Slim Framework

I am fairly new to REST APIs, and I realize there are quite a few questions already posted. However, perusing these has actually left me more confused on how to handle this. I have created a REST API using Slim Framework which I am simply using to…
Drew
  • 2,601
  • 6
  • 42
  • 65
17
votes
1 answer

How do I manually initiate the 404 handler in Slim 3?

We already know how to add a custom 404 notFoundHandler in Slim 3: $container['notFoundHandler'] = function ($c) { return function ($request, $response) use ($c) { return $c->view->render($response, 'pages/404.html.twig') …
alexw
  • 8,468
  • 6
  • 54
  • 86
17
votes
6 answers

Silex vs SLIM PHP Framework

We have narrow down our search between Silex and Slim PHP frameworks for routing our REST APIs on our Apache/PHP/MySQL Server. Both seem to have good reviews. Silex has probably a bigger community because it came from Symfony. But the documentation…
17
votes
3 answers

How to access a JSON request body of a POST request in Slim?

I'm just a newbie in the Slim framework. I've written one API using Slim framework. A POST request is coming to this API from an iPhone app. This POST request is in JSON format. But I'm not able to access the POST parameters that are sent in a…
user4407686
17
votes
4 answers

Not getting expected response from Guzzle

I'm trying to build an endpoint that forwards the data passed to it to an API using the Slim PHP Framework and I'm having trouble getting my response from a Guzzle request. $app->map( '/api_call/:method', function( $method ) use( $app ){ $client…
Johnathan Barrett
  • 546
  • 2
  • 7
  • 24
16
votes
2 answers

slimframework request->headers don´t read Authorization

i´m trying to implement a simple authorization with slim on serverside and angularJS on client side. For Testing the REST APi i´m using a program called Rested for Mac which allows to send rest calls. I want to deliver, once authorization has…
solick
  • 2,325
  • 3
  • 17
  • 29
15
votes
3 answers

Slim PHP Route in Middleware

In Slim is it possible to get the current route within middleware? class Auth extends \Slim\Middleware{ public function call(){ $currentRoute = $this->app->getRoute(); // Something like this? } } I know you can call…
14
votes
2 answers

Get PUT params with Slim PHP

I searched, but I didn't find an answer. I have a RESTful API to manage a basic CRUD. I'm trying to create an update method using PUT, but I can't retrieve the params values. I'm using Postman to make the requests, my request looks…
bodruk
  • 3,242
  • 8
  • 34
  • 52
13
votes
7 answers

Sub views (layouts, templates) in Slim php framework

I'm trying out the Slim php framework Is it possible to have layouts or sub views in Slim? I'd like to use a view file as a template with variables as placeholders for other views loaded separately. How would I do that?
jfoucher
  • 2,251
  • 2
  • 21
  • 29
13
votes
3 answers

Can't send file as form data using cURL

I am trying to send a cURL request via the command line. Below is my request curl -i http://localhost/test/index.php -X POST -F "name=file.png" -F "content=@/var/www/html/test/file.png" The problem I'm having is that the file isn't getting sent…
Bender
  • 581
  • 1
  • 6
  • 20
12
votes
1 answer

The annotation "@OneToMany" in property was never imported (Doctrine2)

I'm working with Doctrine 2 as an ORM for Slim 3 but I keep getting stuck in the object mapping section when I try to implement a bidirectional relationship /** * Class Resource * @package App * @ORM\Entity * @ORM\Table(name="users",…
clifford_owino
  • 462
  • 1
  • 6
  • 24
12
votes
1 answer

Replace critical section with SRW lock

If the application is targeted on Windows Vista or later, could we replace all critical sections with SRW locks? Since critical section is mutually exclusive, for usage it is equivalent to SRW locks in exclusive mode, right? According to MSDN, SRW…
Reci
  • 4,099
  • 3
  • 37
  • 42
12
votes
1 answer

Authentication in Slim: is a combined middleware, singleton and hook approach smart?

I have written my own authentication controller to perform user authentication in my Slim application. Although it works, I am unsure if this is the way Slim is intended to work. My authentication controller $auth has methods like…
Wilbo Baggins
  • 2,701
  • 3
  • 26
  • 39