Giter Club home page Giter Club logo

slim's Introduction

Slim Framework for PHP 5

Slim is a micro framework for PHP 5 that helps you quickly write simple yet powerful RESTful web applications and APIs. Slim is easy to use for both beginners and professionals. Slim favors cleanliness over terseness and common cases over edge cases. Its interface is simple, intuitive, and extensively documented โ€” both online and in the code itself. Thank you for choosing Slim for your next project. I think you're going to love it.

Features

  • Clean and simple DSL for writing powerful web applications
  • HTTP routing
    • Supports all standard and custom HTTP request methods
    • Route parameters and conditions
    • Route redirects
    • Route passing
    • Route halting
    • Route middleware
    • Named routes and urlFor() helper
  • Easy configuration
  • Easy templating with custom Views (e.g. Twig, Mustache, Smarty)
  • Flash messaging
  • Signed cookies with AES-256 encryption
  • HTTP caching (ETag and Last-Modified)
  • Logging
  • Error handling
    • Custom Not Found handler
    • Custom Error handler
    • Debugging
  • Built upon the Rack protocol
  • Extensible middleware and hook architecture
  • Supports PHP >= 5.2.0

"Hello World" application (PHP >= 5.3)

The Slim Framework for PHP 5 supports anonymous functions. This is the preferred method to define Slim application routes. This example assumes you have setup URL rewriting with your web server (see below).

<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/hello/:name', function ($name) {
    echo "Hello, $name!";
});
$app->run();

"Hello World" application (PHP < 5.3)

If you are running PHP < 5.3, the second argument to the application's get() instance method is the name of a callable function instead of an anonymous function. This example assumes you have setup URL rewriting with your web server (see below).

<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/hello/:name', 'hello');
function hello($name) {
    echo "Hello, $name!";
}
$app->run();

Get Started

Install Slim

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

Setup your webserver

Apache

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

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

Nginx

Your nginx configuration file should contain this code (along with other settings you may need) in your location block:

if (!-f $request_filename) {
    rewrite ^ /index.php last;
}

This assumes that Slim's index.php is in the root folder of your project (www root).

lighttpd

Your lighttpd configuration file should contain this code (along with other settings you may need). This code requires lighttpd >= 1.4.24.

url.rewrite-if-not-file = ("^" => "/index.php")

This assumes that Slim's index.php is in the root folder of your project (www root).

Build Your Application

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

require 'Slim/Slim.php';

Next, initialize the Slim application:

$app = new Slim();

Next, define your application's routes:

$app->get('/hello/:name', function ($name) {
    echo "Hello $name";
});

Finally, run your Slim application:

    $app->run();

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

Documentation

Community

Forum and Knowledgebase

Visit Slim's official forum and knowledge base at http://help.slimframework.com where you can find announcements, chat with fellow Slim users, ask questions, help others, or show off your cool Slim Framework apps.

Twitter

Follow @slimphp on Twitter to receive the very latest news and updates about the framework.

IRC

You can find me, Josh Lockhart, hanging out in the ##slim chat room during the day. Feel free to say hi, ask questions, or just hang out. If you're on a Mac, check out Colloquy; if you're on a PC, check out mIRC; if you're on Linux, I'm sure you already know what you're doing.

Resources

Additional resources (ie. custom Views and plugins) are available online in a separate repository.

https://github.com/codeguy/Slim-Extras

Here are more links that may also be useful.

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 continually improving.

Open Source License

Slim is released under the MIT public license.

http://www.slimframework.com/license

slim's People

Contributors

akzhan avatar benpjohnson avatar bigbluehat avatar bobdia avatar christianchristensen avatar dhaaker avatar ehaas avatar fgalassi avatar hashchange avatar hexa2k9 avatar j4mie avatar jkaflik avatar josedasilva avatar jwpage avatar klaussilveira avatar l15n avatar lukeholder avatar m92o avatar maikg avatar matthewcallis avatar mfprimo avatar munro avatar neverender avatar silentworks avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.