<?php
class Router {
protected $conn;
protected $currentController = "";
protected $currentMethod = "";
protected $params = [];
public function __construct(PDO $conn){
$this->conn = $conn;
}
public function dispatch(){
$url = $this->getUrl();
if(isset($url[4])){
switch($url[4]){
case "events":
$this->currenController = "EventController";
$this->currentMethod = "getEvents";
break;
case "event":
$this->params = $url[5];
$this->currentController = "EventController";
$this->currentMethod = "getEvent";
break;
}
}
$this->currentController = new AppControllersEventController($this->conn);
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
$this->currentController->display();
}
public function getUrl(){
$uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$url = explode("/", $uri);
return $url;
}
}
?>
$url[5] is supposed to be a numeric id for selecting an event or a string namely “?id=1” how can I pass this value to call_user_func_array I’ve seen doing it with preg_match expressions unfortunately I didn’t understand how it works