Problème avec autoload de composer

Par merciful, il y a 5 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.
le voici:
Fatal error: Uncaught Error: Class 'App\NumberHelper' not found in C:\xampp\htdocs\TP\index.php:34 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TP\index.php on line 34

Ce que je fais

Décrivez ici votre code ou ce que vous cherchez à faire
IL s'agit du TP tuto 34 de Apprendre PHP par GRAFICART

Entourez votre cod<?php use App\NumberHelper; require 'vendor/autoload.php'; $pdo = new PDO("sqlite:./data.sql",null,null,[ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE=> PDO:: ERRMODE_EXCEPTION ]); $products = $pdo->query("SELECT*FROM products LIMIT 20")->fetchAll(); //dd($products); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="bootstrap.min.css"> <title>Biens immobiliers</title> </head> <body> <table class="table table-striped"> <thead> <tr> <th>ID</th> <th>Nom</th> <th>Ville</th> <th>Adresse</th> </tr> </thead> <tbody> <?php foreach($products as $product):?> <tr> <td>#<?= $product['id']?></td> <td><?=$product['name']?></td> <td><?= NumberHelper::price($product['price'])?>$</td> <td><?=$product['city']?></td> <td><?=$product['address']?></td> </tr> <?php endforeach ?> </tbody> </table> </body> </html>e pour bien le mettre en forme VOICI le code json: { "require": { "symfony/var-dumper": "^5.1" }, "autoload": { "prs-4":{ "App\\":"src/" } } }

Ce que je veux

Décrivez ici ce que vous cherchez à obtenir

Ce que j'obtiens

J'ai essayer mais cette erreur s'affiche toujours,pourquoi?
Fatal error: Uncaught Error: Class 'App\NumberHelper' not found in C:\xampp\htdocs\TP\index.php:34 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TP\index.php on line 34

2 réponses

Lartak, il y a 5 ans

Bonjour.
Tu as une erreur dans le code du composer.json, ce n'est pas prs-4 mais psr-4, tu as donc une inversion entre les deux premières lettres.

merciful, il y a 5 ans

Bonjour Lartak! merci beaucoup