Bonjours je suis apres refaire une mise a jour de mon PHP avec le tutorial suivant
J'ai un probleme de router not found voir erreur
j'ai installé altorouter/altorouter : composer require altorouter/altorouter:1.2.0
mon github avec le projet : https://github.com/MI7QC/bloguePHP
public/index.php
"`
<?php
require '../vendor/autoload.php';
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
$router = new App\Router(dirname(DIR) . '/views');
$router
->get('/blog', 'post/index', 'blog')
->get('/blog/category', 'category/show', 'category')
->run();
`"
src/Router.php
"`
<?php
namespace App;
class Router {
/*
*@var string
*/
private $viewPath;
/*
*@var AltoRouter
*/
private $router;
public function __construct(string $viewPath)
{
$this->viewPath = $viewPath;
$this->router = new \AltoRouter();
}
public function get(string $url, string $view, ?string $name = null): self
{
$this->router->map('GET', $url, $view, $name);
return $this;
}
public function run(): self
{
$match = $this->router->match();
$view = $match['target'];
ob_start();
require $this->viewPath . DIRECTORY_SEPARATOR . $view . '.php';
$content = ob_get_clean();
require $this->viewPath . DIRECTORY_SEPARATOR . 'layouts/default.php';
return $this;
}
}
`"
composer.json
" { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "altorouter/altorouter": "1.2.0", "symfony/var-dumper": "^5.2", "filp/whoops": "^2.9" } } "
Ce que je veux
J'aimerais que les route soient fonctionelle quand j'écris http://localhost:8000/blog.
Ce que j'obtiens
j'obtiens une erreur de Class 'App\Router' not found pourtant je relis le code et tout semble bien connecter l'un à lautre.