Slim

Overview

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs. At its core, Slim is a dispatcher that receives an HTTP request, invokes an appropriate callback routine, and returns an HTTP response. That's it.


Getting started

Create an index.php file and type the following

<?php
require '../vendor/autoload.php';

// Create and configure Slim app
$config = ['settings' => [
  'addContentLengthHeader' => false,
]];
$app = new \Slim\App($config);

// Define app routes
$app->get('/hello/{name}', function ($request, $response, $args) {
  return $response->write("Hello " . $args['name']);
});

// Run app
$app->run();

To remove index.php from the url make sure you have .htaccess file in your html folder with the following contents

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Comments (0)

Search Here