编辑:已解决。我刚刚降级到 slim 3。
我收到以下错误消息。我已经尝试过“composer require slim/http”和“composer require slim/psr7”。
未捕获的运行时异常:无法检测到任何 PSR-17 ResponseFactory 实现。请安装受支持的实现才能使用AppFactory::create()。有关支持的实现列表,请参阅https://github.com/slimphp/Slim/blob/4.x/README.md 。在 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php:166 堆栈跟踪:#0 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim /Factory/AppFactory.php(92): Slim\Factory\AppFactory::defineResponseFactory() #1 /Applications/XAMPP/xamppfiles/htdocs/MyApi/public/index.php(12): Slim\Factory\AppFactory::create () #2 {main} 抛出在 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php 第 166 行
小智 5
我在 Slim 4 上遇到了同样的问题,但我通过使用作曲家添加 slim / psr7 解决了它。尝试在此之后发出命令“composer dump”。下面是文件“composer.json”和“index.php”的情况
我的作曲家.json;
{
"name": ".../...",
"description": "....",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "....",
"email": "......."
}
],
"minimum-stability": "dev",
"require": {
"slim/slim": "4.*",
"slim/psr7": "dev-master"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的index.php;
<?php
// https://github.com/slimphp/Slim/blob/4.x/README.md
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
*
* In order for the factory to work you need to ensure you have installed
* a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
* ServerRequest creator (included with Slim PSR-7)
*/
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
/**
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
// My first Route
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello World!");
return $response;
});
// Run app
$app->run();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7159 次 |
| 最近记录: |