Slim README

The project's README from github.com/slimphp/Slim. As one markdown file: README.md.

Slim Framework

Build Status Coverage Status Total Downloads License

Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs.

Installation

It's recommended that you use Composer to install Slim.

composer require slim/slim

This will install Slim and all required dependencies. Slim requires PHP 7.4 or newer.

Choose a PSR-7 Implementation & 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. A few notable ones:

Slim-Http Decorators

Slim-Http is a set of decorators for any PSR-7 implementation that we recommend is used with Slim Framework. To install the Slim-Http library simply run the following command:

composer require slim/http

The ServerRequest and Response object decorators are automatically detected and applied by the internal factories. If you have installed Slim-Http and wish to turn off automatic object decoration then you can use the following statements:

<?php

use Slim\Factory\AppFactory;
use Slim\Factory\ServerRequestCreatorFactory;

AppFactory::setSlimHttpDecoratorsAutomaticDetection(false);
ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(false);

$app = AppFactory::create();

// ...

Hello World using AppFactory with PSR-7 auto-detection

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:

Then create file 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';

// Instantiate App
$app = AppFactory::create();

// Add error middleware
$app->addErrorMiddleware(true, true, true);

// Add routes
$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write('<a href="/hello/world">Try /hello/world</a>');
    return $response;
});

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

$app->run();

You may quickly test this using the built-in PHP server:

php -S localhost:8000 -t public

Going to http://localhost:8000/hello/world will now display "Hello, world".

For more information on how to configure your web server, see the Documentation.

Tests

To execute the test suite, you'll need to install all development dependencies.

git clone https://github.com/slimphp/Slim
composer install
composer test

Contributing

Please see CONTRIBUTING for details.

Learn More

Learn more at these links:

Security

If you discover security related issues, please email [email protected] instead of using the issue tracker.

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of Slim and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. Contribute.

Financial Contributors

Become a financial contributor and help us sustain our community. Contribute

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. Contribute

License

The Slim Framework is licensed under the MIT license. See License File for more information.

Slim (slimphp/Slim)

Searching Database…

12.3K ·GitHub
这是什么?Slim 是一个 PHP 微框架,帮你快速编写简单却强大的 Web 应用和 API。
它是微框架还是全栈框架?是微框架:Slim 保持核心精简,让你自己组装整套技术栈,首先从你选择的 PSR-7 实现开始。
怎么安装并跑起第一个应用?用 Composer 安装 Slim——它会一并拉取 Slim 和所有必需的依赖。README 随后会带你在单个 public/index.php 文件里完成一个 hello world。
开始之前我需要装好哪些东西?PHP 7.4 或更新版本,加上 Composer;另外在安装过程中你还要选择并安装一个 PSR-7 实现包。
PHP 内置服务器够用于生产环境吗?它只建议用来快速测试;对于真正的托管部署,README 会指引你去阅读配置 Web 服务器的文档。
Slim 用的是什么许可证——公司使用需要付费吗?MIT 许可证,可以免费用于任何项目。公司可以通过 Tidelift Subscription 购买商业支持和维护服务。
我该选哪个 PSR-7 实现?可选的有 Slim-Psr7(Slim 团队官方出品)、httpsoft/http-message(据 README 所述是最快、最严格、最轻量的)、Nyholm/psr7(速度几乎相当)、Guzzle/psr7 和 laminas-diactoros。任何一个都能让 AppFactory 自动识别。
Slim 自带请求和响应对象吗?不自带——项目推荐使用 Slim-Http,这是一组装饰器,可以包装任何 PSR-7 实现。安装之后它们会被自动检测并应用,你也可以关闭自动装饰功能。
最小的 Slim 应用长什么样?只有一个文件:创建 public/index.php,用 AppFactory::create() 构建应用,然后调用 run()。已用 PHP 内置服务器测试过,页面会显示 'Hello, world'。
What are similar projects?flask, echo, express, martini, guzzle, axum, sinatra, Rocket
Creator
slimphp
Size
7.1 MB
Stars
12.3K
Age
16y
Commits · 90 Days