|
| 1 | +<?php |
| 2 | + |
| 3 | +require 'src/Nanite.php'; |
| 4 | +require 'src/functions.php'; |
| 5 | + |
| 6 | +get('/', function () { |
| 7 | +?> |
| 8 | + <h1>Nanite Example</h1> |
| 9 | + <h2>Post</h2> |
| 10 | + <form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post"> |
| 11 | + <input type="text" name="name" /> |
| 12 | + <button type="submit">Submit</button> |
| 13 | + </form> |
| 14 | + <h2>Put</h2> |
| 15 | + <form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post"> |
| 16 | + <input type="hidden" name="_method" value="PUT" /> |
| 17 | + <input type="text" name="name" /> |
| 18 | + <button type="submit">Submit</button> |
| 19 | + </form> |
| 20 | + <h2>Patch</h2> |
| 21 | + <form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post"> |
| 22 | + <input type="hidden" name="_method" value="PATCH" /> |
| 23 | + <input type="text" name="name" /> |
| 24 | + <button type="submit">Submit</button> |
| 25 | + </form> |
| 26 | + <h2>Delete</h2> |
| 27 | + <form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/123/delete') ?>" method="post"> |
| 28 | + <input type="hidden" name="_method" value="DELETE" /> |
| 29 | + <button type="submit">Delete</button> |
| 30 | + </form> |
| 31 | +<?php |
| 32 | +}); |
| 33 | + |
| 34 | +get('/test', function () { |
| 35 | + echo "Test page"; |
| 36 | +}); |
| 37 | + |
| 38 | +post('/test', function () { |
| 39 | + $name = empty($_POST['name']) ? 'World' : $_POST['name']; |
| 40 | + echo "Hello, {$name}"; |
| 41 | +}); |
| 42 | + |
| 43 | +put('/test', function () { |
| 44 | + echo 'Put: ' . $_POST['name']; |
| 45 | +}); |
| 46 | + |
| 47 | +patch('/test', function () { |
| 48 | + echo 'Patch: ' . $_POST['name']; |
| 49 | +}); |
| 50 | + |
| 51 | +delete('/([0-9]+)/delete', function ($id) { |
| 52 | + echo "Deleted: {$id}"; |
| 53 | +}); |
0 commit comments