Problème avec le tableau dynamique des biens immobiliers

Par UgZ, il y a 4 ans


Base de données MySQL

Décrivez ici votre problème ou ce que vous cherchez à faire.

Le tableau en question :

<table class="table table-striped"> <thead> <tr> <th><?= TableHelper::sort('id', 'ID', $_GET) ?></th> <th><?= TableHelper::sort('name', 'Nom', $_GET) ?></th> <th><?= TableHelper::sort('price', 'Prix', $_GET) ?></th> <th><?= TableHelper::sort('city', 'Ville', $_GET) ?></th> <th><?= TableHelper::sort('address', 'Adresse', $_GET) ?></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> <tbody>

La class TableHelper qui apparemment ne convient pas (elle est identique à la vidéo) :

<?php namespace App; class TableHelper { const SORT_KEY = 'sort'; const DIR_KEY = 'dir'; public static function sort(string $sortKey, string $label, array $data): string { $sort = $data[self::SORT_KEY] ?? null; $direction = $data[self::DIR_KEY] ?? null; $icon = ""; if ($sort === $sortKey) { $icon = $direction === 'asc' ? "^" : 'v'; } $url = URLHelper::withParams($data, [ 'sort' => $sortKey, 'dir' => $direction === 'asc' && $sort === $sortKey ? 'desc' : 'asc' ]); return <<<HTML <a href="?$url">$label $icon</a> HTML; } }

Ce que je veux

J'aimerai que le tableau s'affiche correctement.

Ce que j'obtiens

J'obtiens une erreur php :
"Fatal error: Uncaught Error: Class 'App\TableHelper' not found in C:\wamp64\www\projet\tableau\index.php on line 71"
et
"Error: Class 'App\TableHelper' not found in C:\wamp64\www\projet\tableau\index.php on line 71"
La ligne 71 est la ligne suivante :

<th><?= TableHelper::sort('id', 'ID', $_GET) ?></th>

Si besoin de plus de détails je reste disponible, merci d'avance.

4 réponses

Carouge10, il y a 4 ans

ou fais tu ton appel de classe ?

UgZ, il y a 4 ans

Bonjour, j'utilise là :
Au tout début du code php

use App\NumberHelper; // Organisation if (!empty($_GET['sort']) && in_array($_GET['sort'], $sortable)) { $direction = $_GET['dir'] ?? 'asc'; if (!in_array($direction, ['asc', 'desc'])) { $direction = 'asc'; } $query .= " ORDER BY " . $_GET['sort'] . " $direction"; }
Carouge10, il y a 4 ans

?
et pour tablehelper ?
car c'est lui qui