# 安装
## 系统需求
* Web server with URL rewriting
* PHP 7.1 or newer
## 步骤1:安装Composer
Don’t have Composer? It’s easy to install by following the instructions on their[download](https://getcomposer.org/download/)page.
## 第二步:安装Slim
We recommend you install Slim with[Composer](https://getcomposer.org/). Navigate into your project’s root directory and execute the bash command shown below. This command downloads the Slim Framework and its third-party dependencies into your project’s`vendor/`directory.
我们建议您安装Slim与Composer。导航到项目的根目录并执行如下所示的bash命令。该命令将Slim框架及其第三方依赖项下载到项目的 vendor/ 目录中。
~~~bash
composer require slim/slim
~~~
## 步骤3:安装PSR-7实现和ServerRequest Creator
Before you can get up and running with Slim you will need to choose a PSR-7 implementation that best fits your application. In order for auto-detection to work and enable you to use`AppFactory::create()`and`App::run()`without having to manually create a`ServerRequest`you need to install one of the following implementations:
在使用Slim之前,您需要选择最适合您的应用程序的PSR-7实现。为了使自动检测工作,并使您能够使用' AppFactory::create() '和' App::run() '无需手动创建' ServerRequest ',您需要安装以下实现之一:
### [Slim PSR-7](https://github.com/slimphp/Slim-Psr7)
~~~bash
composer require slim/psr7
~~~
### [Nyholm PSR-7](https://github.com/Nyholm/psr7)and[Nyholm PSR-7 Server](https://github.com/Nyholm/psr7-server)
~~~bash
composer require nyholm/psr7 nyholm/psr7-server
~~~
### [Guzzle PSR-7](https://github.com/guzzle/psr7)and[Guzzle HTTP Factory](https://github.com/http-interop/http-factory-guzzle)
~~~bash
composer require guzzlehttp/psr7 http-interop/http-factory-guzzle
~~~
### [Zend Diactoros](https://github.com/zendframework/zend-diactoros)
~~~bash
composer require zendframework/zend-diactoros
~~~
## 步骤4 :创建实例
~~~php
<?php
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('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello world!");
return $response;
});
$app->run();
~~~
- 开始
- 安装
- 升级指南
- Web服务器
- 概念
- 生命周期
- PSR 7
- 中间件
- 依赖容器
- 实例 及通知和警告处理
- Request
- 请求方法
- 请求头信息
- 请求主体
- 上传的文件
- 请求帮助
- 路由对象
- Response
- 响应状态
- 响应标头
- 响应体
- 返回JSON
- 视图模板
- 路由
- 创建路由
- 路由回调
- 路由策略
- 路线占位符
- 路由名
- 路由组
- 路由中间件
- 路由表达式缓存
- 容器识别解析
- 封装中间件
- 路由的中间件
- 错误处理中间件
- 方法重写的中间件
- 输出缓冲中间件
- 内容长度中间件
- 扩展功能
- 以 / 结尾的路由模式
- 获取当前路由
- 设置CORS
- 使用POST表单上传文件
- 第三方组件
- slim-session
- auth
- slim-api-skeleton
- dir