• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » PHP » Slim Framework Basic Tutorial For Beginner, A Micro Framework For PHP

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

By Sigit Prasetya Nugroho ∙ February 27, 2017 ∙ PHP ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

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.

Table of Contents

  • 1 What is Slim Framework?
    • 1.1 Slim Framework Installation

What is Slim Framework?

Slim Framework built by Josh Lockhart, a senior developer of newmediacampaigns.com 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 https://getcomposer.org/installer | 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:

1
2
3
4
5
6
7
8
9
10
<?php
 
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/profile/{name}', function($request, $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Welcome back $name");
return $response;
});
$app->run();

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

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

3. Please try on your browser

http://localhost/basicslim/public/profile/sigit

Slim Framework Simple REST API Php Example

Reference

https://www.slimframework.com/

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

Another PHP Related Post :

  • Tutorial Create Simple POS Using ReactJS And Laravel Lumen Part 1
  • How To Replace String With Another String In PHP
  • Login Page – Tutorial CRUD Client and API Server Using JQuery And Lumen Part 2
  • Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
  • How To Solve Problems Illegal mix of collations (latin1_swedish_ci,IMPLICIT) In Laravel
  • How To Resolve No ‘Access-Control-Allow-Origin’ Header In Lumen

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

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

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) lumen api (4) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (8) Publisher Tips (5) react (6) Reactjs (9) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2022 Seegatesite.com