How to install PHP framework Slim

Source: Internet
Author: User
Tags install php php framework

The simplest and most straightforward method--Download the zip file to GitHub, slim GitHub "link". After extracting the "1" Slim folder, "2". htaccess files and "3" index.php files are copied to the WWW directory. If you see the following page, slim installation is successful.



Figure 2 Slim installation success


4. Simple modification and testing

Slim provides a complete rest framework that supports GET, POST, put, and delete methods to make index.php modifications easier. You can familiarize yourself with the basic framework and usage of slim from the following code.


[PHP] view plain copy


<?php/** * Step 1:require the Slim Framework * If You is not using Composer, you need to Require the * Slim F  Ramework and register its PSR-0 autoloader.  * * If you is using Composer, you can skip this step.    */require ' slim/slim.php ';    \slim\slim::registerautoloader (); /** * Step 2:instantiate a Slim application * * This example instantiates a Slim application using * Its default sett Ings. However, you'll usually configure * your Slim application now by passing an associative array * of setting names and V  Alues into the application constructor.    */$app = new \slim\slim (); /** * Step 3:define the Slim application routes * * Here we Define several Slim application routes this respond * to Appropriate HTTP request methods. In this example, the second * argument for ' slim::get ', ' Slim::p ost ', ' Slim::p ut ', ' Slim::p atch ', and ' Slim::d elete ' * I  s an anonymous function. *//GET Route $app->get ('/', function () {echo ' HeLlo Slim ';    }  );      Post Route $app->post ('/post ', function () {echo ' This is a post route ';    }  );      Put Route $app->put ('/put ', function () {echo ' This is a put route ';    }  );  Patch Route $app->patch ('/patch ', function () {echo ' This is a patch route ';    });      Delete route $app->delete ('/delete ', function () {echo ' This is a delete route ';    }  ); /** * Step 4:run the Slim application * * This method should is called last.  This executes the Slim application * and returns the HTTP-response to the HTTP client.        */$app->run ();  Then open the browser input localhost will only see the following, in fact, the browser using the Get method, in the Slim get route output Hello Slim.      $app->post ('/post ', function () {echo ' This is a post route '; }  );

In slim, '/post ' is a relative path, and the path can support variables. function () is a subsequent processing function. Other HTTP methods are similar.



Figure 3 Slim Get route

Other types of test methods can be used with the Curl tool

"1" test post

Curl--request POST Http://localhost/post

"2" Test put method

Curl--request PUT http://localhost/p ut

"3" Test Delete

Curl--request DELETE http://localhost/ Delete

"Firefox Browser"

If you don't like using the Curl tool, you can also choose the HttpRequest tool in Firefox, then the command operation becomes a pleasant GUI operation.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.