M
M
Miku Hatsune2015-12-10 19:22:37
symfony
Miku Hatsune, 2015-12-10 19:22:37

Why is Class 'Symfony\Component\HttpFoundation\Request' not found?

I ran into a problem in symfony - the autoloader does not load the class.
autoload.php is like this:

<?php
require_once 'vendor/class-loader/UniversalClassLoader.php';
 
use Symfony\Component\ClassLoader\UniversalClassLoader;
 
$loader = new UniversalClassLoader();

$loader->registerNamespaces([
    'Symfony\Component\HttpFoundation' => 'vendor/http-foundation/'
]);

$loader->register();

When executing this code, there are no errors, but in index.php, including autoload.php and trying to use httpFoundation - an error, the class was not found.
index.php code:
<?php
require_once '../framework/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$request = Request::createFromGlobals();
$input = $request->get('name', 'World');
$response = new Response(sprintf('Hello %s', htmlspecialchars($input, ENT_QUOTES, 'UTF-8')));
$response->send();

But the question is why and how to fix it? I checked the path, the files are there...
b24ec7bd4ea44aec9b2dd69ffa6d0fa1.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2015-12-10
@Hatsune-Miku

Use composer as an autoloader and don't worry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question