Slim 是一个很是优雅的 PHP 微框架,很是适合作API,支持多种http请求方式,好比get,post,delete,put等php
安装使用Composer数组
composer require slim/slim
vendor\slim\slim\index.php浏览器
<?php require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); // 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'; } ); $app->run();
可使用火狐浏览器中的HTTPRequest工具测试app
Slim 框架提供了两种方式对其进行配置。composer
一种是在生成实例的时候进行参数设置,另外一种则是在生成实例以后,设置参数能够在生成实例的时候以数组的形式传递给 Slim 的构造函数框架
定义设置函数
$app = new Slim(array( 'debug' => true ));
实例生成以后工具
$app->config(array( 'debug' => true, 'templates.path' => ' ../templates' ));
$settingValue = $app->config('templates.path'); // 返回 "../templates"
获取某项配置post