What is SLIM Framework?
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.”
Called micro framework because Slim framework which focus on the basic needs required of a web application such as: received a HTTP request, send request to appropriate code, and restore HTTP responses.
How to install SLIM Framework?
Before readers install SLIM framework it would be nice readers adjust a PHP
version used. There are two requirements which readers must fullfill.
1. We need a web server like Nginx or Apache.
3. Slim 3 support PHP Version 5.5 or latest
For installing Slim we need to install web server, here we have using xampp for Apache server and also we have to install composer.
1. Manually installing the slim framework
2. Installing Slim from slim skeleton.
Step 1: Create slim project
The above command will create a composer.json file in your project root:
Step 2: Create new filw index.php add required dependencies.
Now just create index.php file containing:
Now goto browser and hit testSlim url like http://localhost:8080/firstSlim you will see hello World. That’s it.
composer require slim/twig-view
To test the working of slim add following code in index.php for test. In root folder create create src/public, add two file index.php and .httaccess. In index.php add the following code
In .httaccess add following code
To make your life easier, you should create a .htaccess file that defines a clean URL structure. In the public directory, make a .htaccess file and add the following code in it. This will provide a clean URL structure for the PHP file. (this just means that you don’t have to include PHP filenames in the URL calls). If the index file is located in a different folder (for instance, the public folder) and the .htaccess file is on the root, you can insert the full path of the index file in the last line:
RewriteRule ^ public/index.php [QSA,L]
we can access by
php -S localhost:8000 or
Upgrade slim 3.0 to 3.5: first change composer.json and run