Я хочу создать ссылку на динамически создаваемую ссылку, но я не знаю, как это сделать с моим кодом. Вот мой класс Router `
class Router
{
public $routes = [
'GET' => [],
'POST' => []
];
public static function load($file)
{
$router = new static;
require $file;
return $router;
}
public function get($uri, $controller)
{
$this->routes['GET'][$uri] = $controller;
}
public function post($uri, $controller)
{
$this->routes['POST'][$uri] = $controller;
}
public function direct($uri, $requestType)
{
if (array_key_exists($uri, $this->routes[$requestType])) {
return $this->routes[$requestType][$uri];
}
throw new Exception('No route defined for this URI.');
}
}
и вот моя страница маршрутов
<?php
$router->get('', 'controllers/index.php');
$router->get('message', 'controllers/message.php');
$router->get('loginForm', 'controllers/loginForm.php');
$router->get('register', 'controllers/register.php');
на своей странице с html я поместил ссылку с динамической ссылкой href='displayPost<?php echo $image->id; ?>
, но я не уверен, как добавить этот $ image-> id; часть в моем списке маршрутизатора и классе, чтобы сделать динамические URL.