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
8
votes
8 answers

Slim 3 Framework + Cookies

I've been using Slim Framework 2 for a while but want to switch to the newest version 3. When reading the upgrade guide, I was a bit bummed about them simply stating that "cookies has been removed from the core" and referring to the FIG Cookies…
skizzo
  • 393
  • 1
  • 3
  • 13
8
votes
1 answer

too many connections using eloquent orm and mysql

I'm using SLIM Framework with Laravel's Eloquent ORM for REST APIs. Recently I faced a problem of too many connections. During one request URI, I need to make several Get and Set calls to mySql DB. This opens connections on every DB transaction I…
Hemant Shekhawat
  • 190
  • 2
  • 11
8
votes
1 answer

PHP Slim Framework: The requested URL was not found on this server

For one of the projects, i am using Slim Framework http://www.slimframework.com/ to create restful APIs in PHP. I did a manual install for the framework by copying it in the PHP project folder using instructions at https://github.com/slimphp/Slim.…
CodeMonkey
  • 2,265
  • 9
  • 48
  • 94
8
votes
7 answers

Slim Framework Base URL

I'm new to Slim Framework. How to get the base URL like with the Codeigniter function base_url()? Thanks
user1285107
7
votes
1 answer

Generate a Paseto V2 Public Key/Token in PHP, Verify in Node.js

Preface: What is Paseto?: https://developer.okta.com/blog/2019/10/17/a-thorough-introduction-to-paseto I am using the PHP library for Paseto from here I am using the Node.js Paseto lib from here I have been able to successfully achieve the…
Woodrow
  • 2,740
  • 1
  • 14
  • 18
7
votes
3 answers

Able to get collection, but not filtered data in production version of Slim app using Eloquent

I've been working on a Slim 2 and have just recently started deploying to a production server. Everything seems to be working okay so far. I'm able to log in so I know that I'm connecting to the database just fine. It recognized who I'm logged in as…
user2530671
  • 428
  • 3
  • 13
7
votes
1 answer

Dependency Injection Slim Framework 3

I'm using Slim Framework 3 to create an API. The app structure is: MVCP (Model, View, Controller, Providers). Is it possible to have Slim Dependency Inject all my classes? I'm using composer to autoload all my dependencies. My directory structure…
Kearney Taaffe
  • 647
  • 8
  • 20
7
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,952
  • 8
  • 30
  • 63
7
votes
1 answer

Uploading a file with twig and Slim framework (Version 2) - PHP

I'm using UserFrosting a user management system and I'm having some trouble uploading a file through form post, this is what I tried This is how my twig file looks.
Gerald Hughes
  • 5,771
  • 20
  • 73
  • 131
7
votes
1 answer

Route parameters with Slim 3 & built-in PHP server

I'm having problems getting routes with parameters to work in Slim 3 RC. $app->get('/hello/:name', function($req, $res, $args) { echo "Hello {$name}"; }); Visiting /hello/joe results in 404. Other routes work fine, e.g.: $app->get('/',…
gazareth
  • 1,135
  • 10
  • 26
7
votes
1 answer

Is it appropriate to use Twig to generate pure JSON responses?

I'm trying to take the result of an Eloquent query, and output its results as a JSON response. My application uses Slim and Twig to generate HTML responses, however I am uncertain if I should be using Twig to generate JSON as well. I know that I…
alexw
  • 8,468
  • 6
  • 54
  • 86
7
votes
1 answer

How can I create a PHPDoc for magic properties outside of the class definition?

PHPDoc provides the @var tag, which should work even for variables declared outside of a class. However, this does not seem to work if I define the variable as a magic member of an object: /** @var $app->translator \Fortress\MessageTranslator…
alexw
  • 8,468
  • 6
  • 54
  • 86
7
votes
2 answers

Access-Control-Origin within Slim Framework and Ember.js

After reading many questions/answers I decided to post. I think Slim Framework - jQuery $.ajax request - Method DELETE is not allowed by Access-Control-Allow-Methods sums up most of the information I've found and tried out. I'm using MAMP with PHP…
jrlainfiesta
  • 105
  • 1
  • 2
  • 9
7
votes
3 answers

always_populate_raw_post_data - Trouble accessing request payload from Backbone create

I am trying to save a collection to my database RESTfully using Backbone.js with the SLIM php framework running on my server. Here is my collection: var newUser = this.collection.create( formData, { wait: true, success:…
jagershark
  • 1,162
  • 3
  • 15
  • 27
7
votes
3 answers

Slim PHP: Only catch valid routes with middleware

I'm writing a REST API with Slim. I have written a small middleware to protect the resources so only authenticated users will be able to access them:
user1555863
  • 2,567
  • 6
  • 35
  • 50