forked from phprouter/main
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.php
More file actions
68 lines (53 loc) · 2.17 KB
/
routes.php
File metadata and controls
68 lines (53 loc) · 2.17 KB
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
require_once __DIR__.'/router.php';
// ##################################################
// ##################################################
// ##################################################
// Static GET
// In the URL -> http://localhost
// The output -> Index
get('/', 'views/index.php');
// Dynamic GET. Example with 1 variable
// The $id will be available in user.php
get('/user/$id', 'views/user');
// Dynamic GET. Example with 2 variables
// The $name will be available in full_name.php
// The $last_name will be available in full_name.php
// In the browser point to: localhost/user/X/Y
get('/user/$name/$last_name', 'views/full_name.php');
// Dynamic GET. Example with 2 variables with static
// In the URL -> http://localhost/product/shoes/color/blue
// The $type will be available in product.php
// The $color will be available in product.php
get('/product/$type/color/$color', 'product.php');
// A route with a callback
get('/callback', function(){
echo 'Callback executed';
});
// A route with a callback passing a variable
// To run this route, in the browser type:
// http://localhost/user/A
get('/callback/$name', function($name){
echo "Callback executed. The name is $name";
});
// Route where the query string happends right after a forward slash
get('/product', '');
// A route with a callback passing 2 variables
// To run this route, in the browser type:
// http://localhost/callback/A/B
get('/callback/$name/$last_name', function($name, $last_name){
echo "Callback executed. The full name is $name $last_name";
});
// ##################################################
// ##################################################
// ##################################################
// Route that will use POST data
post('/user', '/api/save_user');
// ##################################################
// ##################################################
// ##################################################
// any can be used for GETs or POSTs
// For GET or POST
// The 404.php which is inside the views folder will be called
// The 404.php has access to $_GET and $_POST
any('/404','views/404.php');