forked from slimphp/Slim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
115 lines (87 loc) · 2.29 KB
/
bootstrap.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*** REQUIRE SLIM ***/
require 'slim/Slim.php';
/*** INITIALIZE SLIM ***/
Slim::init();
/*** CALLBACKS ***/
//Register a "before" callback for PHP >=5.3
Slim::before(function () {
Slim::response()->write('<p>Before!</p>');
});
//Register a "before" callback for PHP <5.3
/*
Slim::before('example_before');
function example_before() {
Slim::response()->write('Before!');
}
*/
//Register an "after" callback for PHP >=5.3
Slim::after(function () {
Slim::response()->write('<p>After!</p>');
});
//Register an "after" callback for PHP <5.3
/*
Slim::after('example_after');
function example_after() {
Slim::response()->write('After!');
}
*/
/*** ROUTES ***/
//Sample GET route for PHP >=5.3
Slim::get('/', function () {
Slim::render('index.php');
});
//Sample GET route for PHP <5.3
/*
Slim::get('/', 'get_example');
function get_example() {
Slim::render('index.php');
}
*/
//Sample POST route for PHP >=5.3
Slim::post('/post', function () {
echo '<p>Here are the details about your POST request:</p>';
print_r(Slim::request());
});
//Sample POST route for PHP <5.3
/*
Slim::post('/post', 'post_example');
function post_example() {
echo '<br/><br/>Here are the details about your POST request:<br/><br/>';
print_r(Slim::request());
}
*/
//Sample PUT route for PHP >=5.3
Slim::put('/put', function () {
echo '<p>Here are the details about your PUT request:</p>';
print_r(Slim::request());
});
//Sample PUT route for PHP <5.3
/*
Slim::put('/put', 'put_example');
function put_example() {
echo '<br/><br/>Here are the details about your PUT request:<br/><br/>';
print_r(Slim::request());
}
*/
//Sample DELETE route for PHP >=5.3
Slim::delete('/delete', function () {
echo '<p>Here are the details about your DELETE request:</p>';
print_r(Slim::request());
});
//Sample DELETE route for PHP <5.3
/*
Slim::delete('/delete', 'delete_example');
function delete_example() {
echo '<br/><br/>Here are the details about your DELETE request:<br/><br/>';
print_r(Slim::request());
}
*/
/*** NAMED ROUTES *****/
Slim::get('/hello/:name', function ($name) {
echo "<p>Hello, $name!</p>";
echo "<p>This route using name \"Bob\" instead of \"$name\" would be: " . Slim::urlFor('hello', array('name' => 'Bob')) . '</p>';
})->name('hello')->conditions(array('name' => '\w+'));
/*** RUN SLIM ***/
Slim::run();
?>