router

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
class Router
{
private $controller;
private $action;
public function start()
{
$url = isset($_GET['_url']) ? $_GET['_url'] : null;
$splits = explode('/', trim($url, '\\/'));
$this->controller = !empty($splits[0]) ? $splits[0] : 'index';
$this->action = !empty($splits[1]) ? $splits[1] : 'index';
}
public function route()
{
$file_path = __ROOT__ . '/modules/' . $this->controller . '/' . $this->action . '.php';
ob_start();
if (file_exists($file_path)) {
require_once $file_path;
} else {
require_once __ROOT__ . '/error/error.php';
}
if (ob_get_level() > 1)
ob_end_flush();
}
}