Slim Framework Basic Tutorial For Beginner, A Micro Framework For PHP

Slim Framework is a Lightweight and powerful PHP framework. Maybe if you heard about a PHP framework that would come to your mind is learning again from the scratch. But I say no to Slim Framework. Armed with a brief knowledge about PHP you can implement the framework rapidly. Slim Framework does indeed deserve juxtaposed with large frameworks such as Laravel, CodeIgniter, etc. In addition to light, we can easily create APIs with PHP quickly.

What is Slim Framework?

Slim Framework built by Josh Lockhart, a senior developer of and he is “the man behind” PHP at The Right Way. According to Josh Lockhart, Slim Framework are:

“PHP micro framework that helps PHP developers quickly and easily write web applications and APIs. Think of it as a core set of tools with which a developer can build amazing things.”

Slim is a micro framework for more emphasis on basic needs such as creating a web application APIs (receiving an HTTP request and send the request along with the results of its response).

If you want to create CRUD applications with PHP for small-scale, this micro framework is very suitable to be used rather than using a fullstack framework.

The main advantages of the Slim framework are:

  • HTTP Router.
  • Middleware.
  • Dependency Injection.
  • PSR-7 Support

Slim Framework Installation

To find out more about the slim framework please visit the official website. The next step I will share how to install slim framework along with a simple example. To install Slim Framework using the composer. In this tutorial I will use ubuntu terminal:

Skip step installation of composer on ubuntu if you already have a composer

Run this script below on your ubuntu terminal
curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

How to Install Slim Framework

composer require slim/slim “^3.0”

How To Use Slim Framework And How To Install It

After the download process is complete, you will find a “vendor” folder in the project directory. Until this stage, the installation has been successful. The next step is how to use the slim framework

How to use the slim framework

1. Make sure the folder structure on your project as follows

Slim Framework Structure Folder

2. Make index.php file in the public folder, and enter the following code:

In the script above, we use Slim Framework to create a route with a GET method that would capture a parameter of the URL. In order for the script work properly, don’t forget to add .htaccess file in the public folder and copy the following code to the .htaccess

3. Please try on your browser


Slim Framework Simple REST API Php Example


Similarly, Slim Framework tutorial part 1 has been completed. Slim Framework usually used to build a REST API, the next time I will share how to create a simple REST API using the slim framework

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.