Fixed index.php navigation
This commit is contained in:
parent
08e5748f1a
commit
92af3f3e2c
34
index.php
34
index.php
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
echo <<<EOD
|
function navi() {
|
||||||
Navigation:
|
echo <<<EOD
|
||||||
<ul>
|
Navigation:
|
||||||
|
<ul>
|
||||||
<li><a href="/">home</a></li>
|
<li><a href="/">home</a></li>
|
||||||
<li><a href="/index.php">index.php</a></li>
|
<li><a href="/index.php">index.php</a></li>
|
||||||
<li><a href="/user/3/edit">edit user 3</a></li>
|
<li><a href="/user/3/edit">edit user 3</a></li>
|
||||||
|
@ -10,47 +11,54 @@ Navigation:
|
||||||
<li><a href="/contact-form">contact form</a></li>
|
<li><a href="/contact-form">contact form</a></li>
|
||||||
<li><a href="/get-post-sample">get+post example</a></li>
|
<li><a href="/get-post-sample">get+post example</a></li>
|
||||||
<li><a href="/test.html">test.html</a></li>
|
<li><a href="/test.html">test.html</a></li>
|
||||||
<li><a href="/aTrailingSlashDoesNotMatters">aTrailingSlashDoesNotMatters</a></li>
|
<li><a href="/aTrailingSlashDoesNotMatter">aTrailingSlashDoesNotMatter</a></li>
|
||||||
<li><a href="/aTrailingSlashDoesNotMatters/">aTrailingSlashDoesNotMatters/</a></li>
|
<li><a href="/aTrailingSlashDoesNotMatter/">aTrailingSlashDoesNotMatter/</a></li>
|
||||||
<li><a href="/theCaseDoesNotMatters">theCaseDoesNotMatters</a></li>
|
<li><a href="/theCaseDoesNotMatter">theCaseDoesNotMatter</a></li>
|
||||||
<li><a href="/thecasedoesnotmatters">thecasedoesnotmatters</a></li>
|
<li><a href="/thecasedoesnotmatter">thecasedoesnotmatter</a></li>
|
||||||
<li><a href="/this-route-is-not-defined">404 Test</a></li>
|
<li><a href="/this-route-is-not-defined">404 Test</a></li>
|
||||||
<li><a href="/this-route-is-defined">405 Test</a></li>
|
<li><a href="/this-route-is-defined">405 Test</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
EOD;
|
EOD;
|
||||||
|
}
|
||||||
|
|
||||||
// Include router class
|
// Include router class
|
||||||
include 'Route.php';
|
include 'Route.php';
|
||||||
|
|
||||||
// Add base route (startpage)
|
// Add base route (startpage)
|
||||||
Route::add('/', function() {
|
Route::add('/', function() {
|
||||||
|
navi();
|
||||||
echo 'Welcome :-)';
|
echo 'Welcome :-)';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Another base route example
|
// Another base route example
|
||||||
Route::add('/index.php', function() {
|
Route::add('/index.php', function() {
|
||||||
|
navi();
|
||||||
echo 'You are not really on index.php ;-)';
|
echo 'You are not really on index.php ;-)';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simple test route that simulates static html file
|
// Simple test route that simulates static html file
|
||||||
// TODO: Fix this for some web servers
|
// TODO: Fix this for some web servers
|
||||||
Route::add('/test.html', function() {
|
Route::add('/test.html', function() {
|
||||||
|
navi();
|
||||||
echo 'Hello from test.html';
|
echo 'Hello from test.html';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Post route example
|
// Post route example
|
||||||
Route::add('/contact-form', function() {
|
Route::add('/contact-form', function() {
|
||||||
|
navi();
|
||||||
echo '<form method="post"><input type="text" name="test"><input type="submit" value="send"></form>';
|
echo '<form method="post"><input type="text" name="test"><input type="submit" value="send"></form>';
|
||||||
}, 'get');
|
}, 'get');
|
||||||
|
|
||||||
// Post route example
|
// Post route example
|
||||||
Route::add('/contact-form', function() {
|
Route::add('/contact-form', function() {
|
||||||
|
navi();
|
||||||
echo 'Hey! The form has been sent:<br>';
|
echo 'Hey! The form has been sent:<br>';
|
||||||
print_r($_POST);
|
print_r($_POST);
|
||||||
}, 'post');
|
}, 'post');
|
||||||
|
|
||||||
// Get and Post route example
|
// Get and Post route example
|
||||||
Route::add('/get-post-sample', function() {
|
Route::add('/get-post-sample', function() {
|
||||||
|
navi();
|
||||||
echo 'You can GET this page and also POST this form back to it';
|
echo 'You can GET this page and also POST this form back to it';
|
||||||
echo '<form method="post"><input type="text" name="input"><input type="submit" value="send"></form>';
|
echo '<form method="post"><input type="text" name="input"><input type="submit" value="send"></form>';
|
||||||
if (isset($_POST['input'])) {
|
if (isset($_POST['input'])) {
|
||||||
|
@ -64,16 +72,19 @@ Route::add('/get-post-sample', function() {
|
||||||
// Also users could inject SQL statements or other untrusted data if you use (.*)
|
// Also users could inject SQL statements or other untrusted data if you use (.*)
|
||||||
// You should better use a saver expression like /user/([0-9]*)/edit or /user/([A-Za-z]*)/edit
|
// You should better use a saver expression like /user/([0-9]*)/edit or /user/([A-Za-z]*)/edit
|
||||||
Route::add('/user/(.*)/edit', function($id) {
|
Route::add('/user/(.*)/edit', function($id) {
|
||||||
|
navi();
|
||||||
echo 'Edit user with id '.$id.'<br>';
|
echo 'Edit user with id '.$id.'<br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Accept only numbers as parameter. Other characters will result in a 404 error
|
// Accept only numbers as parameter. Other characters will result in a 404 error
|
||||||
Route::add('/foo/([0-9]*)/bar', function($var1) {
|
Route::add('/foo/([0-9]*)/bar', function($var1) {
|
||||||
|
navi();
|
||||||
echo $var1.' is a great number!';
|
echo $var1.' is a great number!';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Crazy route with parameters
|
// Crazy route with parameters
|
||||||
Route::add('/(.*)/(.*)/(.*)/(.*)', function($var1,$var2,$var3,$var4) {
|
Route::add('/(.*)/(.*)/(.*)/(.*)', function($var1,$var2,$var3,$var4) {
|
||||||
|
navi();
|
||||||
echo 'This is the first match: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br>';
|
echo 'This is the first match: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,27 +97,32 @@ Route::add('/foo/bar/foo/bar', function() {
|
||||||
|
|
||||||
// Trailing slash example
|
// Trailing slash example
|
||||||
Route::add('/aTrailingSlashDoesNotMatter', function() {
|
Route::add('/aTrailingSlashDoesNotMatter', function() {
|
||||||
|
navi();
|
||||||
echo 'a trailing slash does not matter<br>';
|
echo 'a trailing slash does not matter<br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Case example
|
// Case example
|
||||||
Route::add('/theCaseDoesNotMatter',function(){
|
Route::add('/theCaseDoesNotMatter',function() {
|
||||||
|
navi();
|
||||||
echo 'the case does not matter<br>';
|
echo 'the case does not matter<br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// 405 test
|
// 405 test
|
||||||
Route::add('/this-route-is-defined', function() {
|
Route::add('/this-route-is-defined', function() {
|
||||||
|
navi();
|
||||||
echo 'You need to patch this route to see this content';
|
echo 'You need to patch this route to see this content';
|
||||||
}, 'patch');
|
}, 'patch');
|
||||||
|
|
||||||
// Add a 404 not found route
|
// Add a 404 not found route
|
||||||
Route::pathNotFound(function($path) {
|
Route::pathNotFound(function($path) {
|
||||||
|
navi();
|
||||||
echo 'Error 404 :-(<br>';
|
echo 'Error 404 :-(<br>';
|
||||||
echo 'The requested path "'.$path.'" was not found!';
|
echo 'The requested path "'.$path.'" was not found!';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a 405 method not allowed route
|
// Add a 405 method not allowed route
|
||||||
Route::methodNotAllowed(function($path, $method) {
|
Route::methodNotAllowed(function($path, $method) {
|
||||||
|
navi();
|
||||||
echo 'Error 405 :-(<br>';
|
echo 'Error 405 :-(<br>';
|
||||||
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
|
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user