'Uncaught Error: Class 'Service\UsersService' not found
I'm trying to run my php-based application, which connects to a mysql DB, launched through docker-compose.
i get this message when i connect to localhost:
Fatal error: Uncaught Error: Class 'Service\UsersService' not found in /var/www/html/dic/users.php:3 Stack trace: #0 /var/www/html/web/index.php(3): require() #1 {main} thrown in /var/www/html/dic/users.php on line 3
user.php
<?php
return new Service\UsersService(
require "../config/db-connection.php"
);
UsersService.php
<?php
namespace Service;
use Entity\User;
use PDO;
class UsersService
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function getLastJoined(): array
{
return $this->db->query(
"SELECT id, joined, name FROM user ORDER BY joined DESC LIMIT 10"
)->fetchAll(PDO::FETCH_CLASS, User::class);
}
public function getById(string $id): ?User
{
$user = $this->db->query("SELECT id, joined, name FROM user WHERE id = " . $this->db->quote($id))->fetchObject(User::class);
return ($user === false) ? null: $user;
}
}
index.php
<?php
$lastJoinedUsers = (require "../dic/users.php")->getLastJoined();
switch (require "../dic/negotiated_format.php") {
case "text/html":
(new Views\Layout(
"Twitter - Newcomers", new Views\Users\Listing($lastJoinedUsers), true
))();
exit;
case "application/json":
header("Content-Type: application/json");
echo json_encode($lastJoinedUsers);
exit;
}
http_response_code(406);
I appreciate any help!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
