首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >超薄PSR-17 ResponseFactory

超薄PSR-17 ResponseFactory
EN

Stack Overflow用户
提问于 2020-05-28 07:01:43
回答 1查看 2.2K关注 0票数 1

编辑:已解析。我刚刚降级到了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

EN

回答 1

Stack Overflow用户

发布于 2021-01-17 04:51:14

我在Slim 4上也遇到了同样的问题,但我通过在作曲家中添加了slim / psr7解决了这个问题。尝试在此之后输入命令'composer dump‘。下面是文件"composer.json“和"index.php”是如何表示的

我的composer.json;

代码语言:javascript
复制
{
    "name": ".../...",
    "description": "....",
    "type": "project",
    "license": "MIT",
    "authors": [
        {
            "name": "....",
            "email": "......."
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "slim/slim": "4.*",
        "slim/psr7": "dev-master"
    }
    }
}

我的index.php;

代码语言:javascript
复制
<?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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62054259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档