forked from steampixel/simplePHPRouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
68 lines (54 loc) · 1.48 KB
/
index.php
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
//require_once "Autoloader.php";
require __DIR__.'/vendor/autoload.php';
use Configuration\Configuration;
use Route\Route;
//config
Configuration::set('basepath', '');
//init routing
Route::init();
//base route (startpage)
Route::add('', function () {
//Do something
echo 'Welcome :-)';
});
//base route
Route::add('index.php', function () {
//Do something
echo 'You are not realy on index.php ;-)';
});
//simple route
Route::add('test.html', function () {
//Do something
echo 'Hello from test.html';
});
//complex route with parameter
Route::add('user/(.*)/edit', function ($id) {
//Do something
echo 'Edit user with id '.$id.'<br/>';
});
//accept only numbers as the second parameter. Other chars will result in a 404
Route::add('foo/([0-9]*)/bar', function ($var1) {
//Do something
echo $var1.' is a great number!';
});
//long route
Route::add('foo/bar/foo/bar', function () {
//Do something
echo 'hehe :-)<br/>';
});
//crazy route with parameters (Will be triggered on the route pattern above too because it matches too)
Route::add('(.*)/(.*)/(.*)/(.*)', function ($var1, $var2, $var3, $var4) {
//Do something
echo 'You have entered: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br/>';
});
//Add a 404 Not found Route
Route::add404(function ($url) {
//Send 404 Header
header('HTTP/1.0 404 Not Found');
echo '404 :-(<br/>';
echo $url.' not found!';
});
Route::run();