diff --git a/index.php b/index.php index b4bc1de..83f8a79 100644 --- a/index.php +++ b/index.php @@ -1,56 +1,64 @@ -
  • home
  • -
  • index.php
  • -
  • edit user 3
  • -
  • foo 5 bar
  • -
  • long route example
  • -
  • contact form
  • -
  • get+post example
  • -
  • test.html
  • -
  • aTrailingSlashDoesNotMatters
  • -
  • aTrailingSlashDoesNotMatters/
  • -
  • theCaseDoesNotMatters
  • -
  • thecasedoesnotmatters
  • -
  • 404 Test
  • -
  • 405 Test
  • - +function navi() { + echo << +
  • home
  • +
  • index.php
  • +
  • edit user 3
  • +
  • foo 5 bar
  • +
  • long route example
  • +
  • contact form
  • +
  • get+post example
  • +
  • test.html
  • +
  • aTrailingSlashDoesNotMatter
  • +
  • aTrailingSlashDoesNotMatter/
  • +
  • theCaseDoesNotMatter
  • +
  • thecasedoesnotmatter
  • +
  • 404 Test
  • +
  • 405 Test
  • + EOD; +} // Include router class include 'Route.php'; // Add base route (startpage) Route::add('/', function() { + navi(); echo 'Welcome :-)'; }); // Another base route example Route::add('/index.php', function() { + navi(); echo 'You are not really on index.php ;-)'; }); // Simple test route that simulates static html file // TODO: Fix this for some web servers Route::add('/test.html', function() { + navi(); echo 'Hello from test.html'; }); // Post route example Route::add('/contact-form', function() { + navi(); echo '
    '; }, 'get'); // Post route example Route::add('/contact-form', function() { + navi(); echo 'Hey! The form has been sent:
    '; print_r($_POST); }, 'post'); // Get and Post route example Route::add('/get-post-sample', function() { + navi(); echo 'You can GET this page and also POST this form back to it'; echo '
    '; 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 (.*) // You should better use a saver expression like /user/([0-9]*)/edit or /user/([A-Za-z]*)/edit Route::add('/user/(.*)/edit', function($id) { + navi(); echo 'Edit user with id '.$id.'
    '; }); // Accept only numbers as parameter. Other characters will result in a 404 error Route::add('/foo/([0-9]*)/bar', function($var1) { + navi(); echo $var1.' is a great number!'; }); // Crazy route with parameters Route::add('/(.*)/(.*)/(.*)/(.*)', function($var1,$var2,$var3,$var4) { + navi(); echo 'This is the first match: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'
    '; }); @@ -86,27 +97,32 @@ Route::add('/foo/bar/foo/bar', function() { // Trailing slash example Route::add('/aTrailingSlashDoesNotMatter', function() { + navi(); echo 'a trailing slash does not matter
    '; }); // Case example -Route::add('/theCaseDoesNotMatter',function(){ +Route::add('/theCaseDoesNotMatter',function() { + navi(); echo 'the case does not matter
    '; }); // 405 test Route::add('/this-route-is-defined', function() { + navi(); echo 'You need to patch this route to see this content'; }, 'patch'); // Add a 404 not found route Route::pathNotFound(function($path) { + navi(); echo 'Error 404 :-(
    '; echo 'The requested path "'.$path.'" was not found!'; }); // Add a 405 method not allowed route Route::methodNotAllowed(function($path, $method) { + navi(); echo 'Error 405 :-(
    '; echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!'; });