Click here to Skip to main content
Click here to Skip to main content

Slim framework installation

, 6 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to install Slim Framework on Ubuntu?

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://www.slimframework.com/install/

Using the code

You need to give 777 -R permissions to your project folder.

Install composer:

curl -s https://getcomposer.org/installer | php

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/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Latika surse
Software Developer (Senior) Fulcrum World Wide
India India
No Biography provided
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 6 Aug 2014
Article Copyright 2014 by Latika surse
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid