Giter Club home page Giter Club logo

slim's Introduction

Slim Framework for PHP 5

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

Features

The Slim Framework for PHP 5 provides the following notable features out-of-the-box:

  • Clean and simple DSL for writing powerful web applications
  • RESTful HTTP routes (GET, POST, PUT, DELETE)
    • Named routes w/ urlFor() helper
    • Route passing
    • Route redirects
    • Route halting
    • Custom Not Found handler
    • Custom Error handler
    • Optional route segments... /archive(/:year(/:month(/:day)))
  • Easy app configuration
  • Easy templating with custom Views (ie. Twig, Smarty, Mustache, ...)
  • Secure sessions
  • Signed cookies with AES-256 encryption
  • Flash messaging
  • HTTP caching (ETag and Last-Modified)
  • Logging
  • Error handling
  • Supports PHP 5+

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

The Slim Framework for PHP 5 supports anonymous functions. This is the preferred method of defining Slim application routes.

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

"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.

<?php
require 'Slim/Slim.php';
Slim::init();
Slim::get('/hello/:name', 'hello');
function hello($name) {
    echo "Hello, $name!";
}
Slim::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 .htaccess

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]

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:

Slim::init();

Next, define your application's routes:

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

Finally, run your Slim application:

Slim::run();

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

Links and Resources

For the most up-to-date information and news, follow the Slim PHP 5 micro framework on Twitter:

http://www.twitter.com/slimphp

Additional resources (ie. custom Views and plugins) are available online in a separate repository so this primary repository remains as light-weight as possible.

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

Other helpful links:

Open Source License

Slim is released under the MIT public license.

http://www.slimframework.com/license

slim's People

Contributors

bobdia avatar christianchristensen avatar fgalassi avatar hexa2k9 avatar j4mie avatar jkaflik avatar josedasilva avatar jwpage avatar l15n avatar matthewcallis avatar munro avatar neverender avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

vijusg

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.