A RESTful micro framework for PHP 5 inspired by Sinatra
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2841 commits behind slimphp:3.x.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Slim Framework for PHP 5

Thank you for choosing Slim, a micro-framework for PHP 5 inspired by Sinatra.


Slim provides the following notable features out-of-the-box:

  • Clean and simple DSL for writing powerful web applications
  • RESTful routes (GET, POST, PUT, DELETE)
    • Named routes w/ urlFor() helper
    • Route passing
    • Route redirects
    • Route halting
    • Custom 404 and Error handlers
  • Easy templating with custom Views (ie. Twig, Smarty, Mustache, ...)
  • HTTP Caching
  • Session handling
  • Logging
  • Error handling
  • Supports PHP 5+

"Hello World" application (PHP 5 >= 5.3)

The Slim Framework supports anonymous routes. This is the preferred method of defining Slim application routes.

require 'slim/Slim.php';
Slim::get('/hello/:name', function ($name) {
    echo "Hello, $name!";

"Hello World" application (PHP 5 < 5.3)

If you are running PHP 5 < 5.3, the second Slim::get parameter will be the name of a callable function instead of an anonymous function.

require 'slim/Slim.php';
Slim::get('/hello/:name', 'hello');
function hello($name) {
    echo "Hello, $name!";

Get Started

Install Slim

Download the Slim Framework and unzip the downloaded file into your virtual host's public directory. Slim will work in a sub-directory, too.

Setup .htaccess

Ensure the .htaccess and bootstrap.php files are in the same public-accessible directory. The .htaccess file should contain this code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ bootstrap.php [QSA,L]

Build Your Application

Your Slim application will be defined in bootstrap.php. First, require the Slim Framework:

require 'slim/Slim.php';

Next, initialize the Slim application:


Next, define your application's routes:

Slim::get('/hello/:name', function ($name) {
	echo "Hello $name";

Finally, run your Slim application:


For more information about building an application with the Slim Framework, refer to the official documentation.

About the Author

Slim is created and maintained by Josh Lockhart, a web developer by day at New Media Campaigns, and a hacker by night.

Slim is in active development, and test coverage is improving rapidly as Slim nears its official 1.0 release.

Links and Resources

Open Source License

Slim is released under the MIT public license.