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
9
votes
2 answers

Eloquent updateOrCreate not updating

I am having trouble using updateOrCreate. The below code is SUCCESSFULLY creating a new row; however when it comes to updating an existing row it doesn't work at all! comm_helpful::updateOrCreate( ['ID' => 1], ['time' =>…
j. marc
  • 333
  • 4
  • 11
9
votes
1 answer

How to authorize google-api-php-client with a slim 3 Rest API?

I'm trying to create a web-based email client which gets all email data from google mail API. I'm using Slim3 for creating a restful API interface. To access google APIs, I'm using Google-API-PHP-Client (Google does have a rest API access and I…
9
votes
4 answers

Slim 3 getParsedBody() always null and empty

I'm am using the Slim Framework Version 3 and have some problems. $app-> post('/', function($request, $response){ $parsedBody = $request->getParsedBody()['email']; var_dump($parsedBody); }); result is always: null Can you help me ?
animatorist
  • 113
  • 1
  • 2
  • 6
9
votes
1 answer

Passing static classes via Dependancy Injection

How is it possible to pass a static class to an object via Dependency Injection? For example Carbon uses static methods: $tomorrow = Carbon::now()->addDay(); I have services that depend on Carbon, and currently I'm using the library in the…
BugHunterUK
  • 8,346
  • 16
  • 65
  • 121
9
votes
4 answers

Slim 3 Middleware Redirect

I want to check if a user is logged in. Therefor I have an Class witch returns true or false. Now I want a middleware which checks if the user is logged in. $app->get('/login',…
Stefan Roock
  • 153
  • 1
  • 5
9
votes
3 answers

Slim 3 Framework how to download file

I'm trying to download a file using the Slim 3 PHP Framework. Slim 2 was fairly straight forward, as I'm sure Slim 3 is too, but I just don't get it. Any help would be appreciated. Based on the documentation here :…
Jim_M
  • 273
  • 1
  • 2
  • 10
9
votes
2 answers

slim php framework image upload put database

I am new to slim php framework, I want to upload an image and put the file name in the database via POST, can some one kindly give me some example code.
Jasonsti
  • 121
  • 1
  • 1
  • 10
9
votes
5 answers

How to refactor long php file of routes (I'm using Slim Framework)

I am using the Slim Framework for a simple crud-style application. My index.php file has become quite long and unwieldy with all the different routes. How can I clean up / refactor this code? For example I have code like the following for all the…
weaveoftheride
  • 4,092
  • 8
  • 35
  • 53
8
votes
3 answers

Upgrading tf.contrib.slim manually to tf 2.0

I have a problem with my python code that uses tf.contrib.slim functionalities and no longer works after upgrading to tensorflow to 2.0. How can I upgrade the following to tf 2.0: import tensorflow.contrib.slim as slim import…
Jonas G.
  • 129
  • 1
  • 1
  • 7
8
votes
3 answers

how to add twig-view in slimframework v4

I'm trying to add twig-view in slim v4 In slim v3, we add twig-view in container $container['view'] = function ($c) { $view = new \Slim\Views\Twig('path/to/templates', [ 'cache' => 'path/to/cache' ]); // Instantiate and add…
mk990
  • 103
  • 1
  • 1
  • 9
8
votes
3 answers

CORS Errors only with 400 bad request react fetch request

I'm trying to make 'POST' request in react but i'm getting a few problems regarding CORS. I was just following what console says and fix them in server side [which is PHP] and client side everything works fine when the status is 200 but when status…
Liam
  • 6,517
  • 7
  • 25
  • 47
8
votes
2 answers

PHP built-in server shows index page instead of static file

I created a project with Slim 3 and Twig using their simplest examples. Folder structure is as follows: - public - index.php - style.css App code in index.php is as follows:
Tarps
  • 1,928
  • 1
  • 11
  • 27
8
votes
1 answer

In PhpStorm warning method 'withJson' not found (Slim Framework)

In PhpStorm I get the warning message "warning method 'withJson' not found" in \Psr\Http\Message\ResponseInterface" at te line: return $response->withJson($toReturn, 200); The code: use \Psr\Http\Message\ServerRequestInterface as Request; use…
Wow
  • 177
  • 1
  • 8
8
votes
4 answers

Slim 3 multiple routes to one function?

I've been looking all over online and can't find anything that tells you how to assign multiple routes to one callback. For example I want to move: $app->get('/sign-in', function($request, $response) { return $this->view->render($response,…
Joe Scotto
  • 10,936
  • 14
  • 66
  • 136
8
votes
2 answers

Slim Framework - splitting code into multiple files other than index.php

On the documentation for Slim Framework, it says In this example application, all the routes are in index.php but in practice this can make for a rather long and unwieldy file! It’s fine to refactor your application to put routes into a…
Andy
  • 5,142
  • 11
  • 58
  • 131