# 安裝
## 系統需求
* 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