Slim 是一个PHP微型框架,它可以帮助你快速开发简单且强大的web应用和API。

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;


下载 & 安装

我们推荐你使用 Composer 依赖管理来安装slim框架。


$ mkdir -p slim-demo/public && cd slim-demo
$ composer require slim/slim:"4.*" slim/psr7
$ touch public/index.php //复制页面最上面的demo代码
$ php -S localhost:8080 -t public public/index.php

开始使用slim最简单的方法是用 Slim-Skeleton创建工程项目,只需要执行如下命令:

$ php composer.phar create-project slim/slim-skeleton:dev-master [my-app-name]

用你的项目名称替换 [my-app-name]这里。


$ cd [my-app-name]; php -S localhost:8080 -t public public/index.php



Slim provides a fast and powerful router that maps route callbacks to specific HTTP request methods and URIs. It supports parameters and pattern matching.


Build your application with concentric middleware to tweak the HTTP request and response objects around your Slim app.

支持 PSR-7

Slim supports any PSR-7 HTTP message implementation so you may inspect and manipulate HTTP message method, status, URI, headers, cookies, and body.

依赖注入 DI

Slim supports dependency injection so you have complete control of your external tools. Use any Container-Interop container.




You can chat with other Slim Framework developers to share code or troubleshoot tricky issues using either Slack or IRC. Our nicks are akrabat, silentworks and codeguy if you have have questions or need assistance.


We can be found on Slack at