多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 安装 ## 系统需求 * 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(); ~~~