没有作曲家?按照下载页面上的说明进行安装很容易。
我们建议您安装带有Composer的 Slim 。导航到项目的根目录并执行如下所示的 bash 命令。此命令将 Slim Framework 及其第三方依赖项下载到项目vendor/
目录中。
composer require slim/slim:"4.*"
在启动并运行 Slim 之前,您需要选择最适合您的应用程序的 PSR-7 实现。为了自动检测工作并使您能够使用AppFactory::create()
而App::run()
无需手动创建,ServerRequest
您需要安装以下实现之一:
composer require slim/psr7
composer require nyholm/psr7 nyholm/psr7-server
composer require guzzlehttp/psr7 "^2"
composer require guzzlehttp/psr7 "^1"
composer require sapphirecat/slim4-http-interop-adapter
composer require laminas/laminas-diactoros
文件:public/index.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();