Introduction
Slim is a tiny PHP framework that helps you quickly developing simple and powerful web applications and web services.
Features
- Slim is very simple and easy to configure.
- Slim is used to rendering template with custom views.
- Slim supports flash messaging.
- It's also stored HTTP caching.
- Slim app should encrypt its HTTP cookies.
- Slim supports the concept of modes.
- Slim will use to built-in error handler if debugging is enable.
Installation
Composer Install
Simple way is to download and extract the Slim Framework into your project directory and require it in your application’s index.php file.
http:
Using the code
You need to give 777 -R permissions to your project folder.
Install composer:
curl -s https:
Install via composer:
composer install
php composer.phar install
You also need to register Slim’s autoloader.
require 'Slim/Slim.php';
Make sure you required Slim.php file that belongs to in Slim folder. Otherwise you won't be able to use Slim framework.
Then invoke this static registerAutoloader() function define into the Slim class. It is necessary to registerAutoloader() function if you won't register nothing will be work.
\Slim\Slim::registerAutoloader();
The next step would be just need to instantiate the \Slim\Slim() class and use referrence as an object, use that object in our code.
$application = new \Slim\Slim();
Define a HTTP GET route:
$application->get(
'/hi/:firstname/:lastname',
function ($first,$last){
echo "Hi!! $first $last";
});
'/hi/:firstname/:lastname' is the URL. If this URL is match then following function will be invoked using GET HTTP method.
function ($first,$last){
echo "Hi!! $first $last";
});
Run the your Slim application:
$application->run();
The URL address like
http://localhost/slimsample/helloslim.php/hello/Bryan/Adams
helloslim.php is my Slim application page.
hi/Bryan/Adams append with the URL address if it would be match to hi/:firstname/:lastname and if it's available the generate the output using passing parameters $first and $last.
Output is,
Hi!! Bryan Adams
Using Slim is very simple. For Advanced knowledge, You can refer following links.
References
http://docs.slimframework.com/
http://www.slimframework.com/