Folder Psr\Http\Message\ don´t exist


#1

HI.
I installed the slim through the composer. The information is ready. Type localhost: 8080 and the slim page appears.
But when I use the php example code, it does not run because the Psr \ Http \ Message \ folder does not exist.
I changed the command line
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
to
use vendor\psr\http-message\scr\ServerRequestInterface as Request;
use vendor\psr\http-message\scr\ResponseInterface as Response;
I changed the command line because those folder were created.

Parse error: syntax error, unexpected ‘-’, expecting ‘,’ or ‘;’ in C:\xampp\htdocs\composer\escola\index.php on line 3

So I renamed the http-message folder to http, created the sub folder message, and put the files inside it.

New error citing path that does not exist in message.php
use InvalidArgumentException;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;


#2

You shouldn’t need to do that. Are you including the autoloader in your index.php or other bootstrapping?

require __DIR__ . '/../vendor/autoload.php';

… or similar?


#3

Hi, tflight.
I copy the php code from the slim page.
https://www.slimframework.com/ :

<?php use vendor\psr\http-message\scr\ServerRequestInterface as Request; use vendor\psr\http-message\scr\ResponseInterface as Response; require 'vendor/autoload.php'; $app = new \Slim\App; $app->get('/hello/{name}', function (Request $request, Response $response, array $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); return $response; }); $app->run();

#4

Then the folder structure Psr \ Http \ Message \ is not necessary as it is importing those classes from the autoloader. You don’t need to move folders around, change their names, etc.


#5

God Morning Tflight.
index.php file in c:\xampp\htdocs\composer\escola
So, when a write in browser :
http://localhost/composer/escola/
PAGE NOT FOUND
http://localhost/composer/escola/teste
Objeto não encontrado! ( object not found )

<?php use psr\http\message\ServerRequestInterface as Request; use psr\http\message\ResponseInterface as Response; require 'vendor/autoload.php'; $app = new Slim\App(); $app->get('/teste', function(Request $request, Response $response, array $args){ return $response->getBody()->write('hello world'); } ); $app->run(); ?>

#6

Resolved. I copied the .htacess file to the folder.
Sorry.!