编辑:已解析。我刚刚降级到了slim 3。
我收到以下错误消息。我已经尝试过"composer require /http“和"composer require /psr7”。
未捕获RuntimeException:无法检测到任何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::determineResponseFactory() #1工厂\ /Applications/XAMPP/xamppfiles/htdocs/MyApi/public/index.php(12):create() #2 {main}在/Applications/XAMPP/xamppfiles/htdocs中抛出第166行上的/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php
发布于 2021-01-17 04:51:14
我在Slim 4上也遇到了同样的问题,但我通过在作曲家中添加了slim / psr7解决了这个问题。尝试在此之后输入命令'composer dump‘。下面是文件"composer.json“和"index.php”是如何表示的
我的composer.json;
{
"name": ".../...",
"description": "....",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "....",
"email": "......."
}
],
"minimum-stability": "dev",
"require": {
"slim/slim": "4.*",
"slim/psr7": "dev-master"
}
}
}我的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();https://stackoverflow.com/questions/62054259
复制相似问题