slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.94k stars 1.95k forks source link

Erro Could not detect any PSR-17 ResponseFactory implementations. #3223

Closed lucascardo12 closed 2 years ago

lucascardo12 commented 2 years ago

PHP Fatal error: Uncaught RuntimeException: Could not detect any PSR-17 ResponseFactory implementations. Please install a supported implementation in order to use AppFactory::create(). See https://github.com/slimphp/Slim/blob/4.x/README.md for a list of supported implementations. in C:\Users\myproject\vendor\slim\slim\Slim\Factory\AppFactory.php:182 Stack trace:

0 C:\Users\myproject\vendor\slim\slim\Slim\Factory\AppFactory.php(93): Slim\Factory\AppFactory::determineResponseFactory()

1 C:\Users\myproject\public\index.php(9): Slim\Factory\AppFactory::create()

2 {main}

thrown in C:\Usersmyproject\vendor\slim\slim\Slim\Factory\AppFactory.php on line 182

my 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('Try /hello/world'); return $response; });

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

$app->run();

odan commented 2 years ago

Have you tried to install a PSR-7 package?

https://www.slimframework.com/docs/v4/start/installation.html#step-3-install-a-psr-7-implementation-and-serverrequest-creator

lucascardo12 commented 2 years ago

Thank you, I was using it wrong.