1. Go to this page and download the library: Download inphinit/teeny library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inphinit / teeny example snippets
$app->action('GET', '/myroute', function () {
echo 'Test!';
});
$app->action('GET', '/myroute', function () {
return 'Test!';
});
$app->action('GET', '/myroute', function () use ($app) {
echo 'HTTP status: ', $app->status();
});
$app->status(404);
$app->action('GET', '/report', function () use ($app) {
$file = 'data/foo.csv';
if (is_file($file)) {
header('Content-Type: text/csv');
readfile($file);
/**
* Note: this is just an example, about sending a file,
* if possible use "X-Sendfile" or equivalent
*/
} else {
$app->status(404);
echo 'Report not found';
}
});
$app->action('GET', '/user/<user>', function ($params) {
var_dump($params);
});
array(2) {
["user"]=>
string(3) "mary"
}
$app->action('GET', '/article/<name>-<id>', function ($params) use ($app) {
// Only ID numerics are valids
if (ctype_digit($params['id'])) {
echo 'Article ID: ', $params['id'], '<br>';
echo 'Article name: ', $params['name'];
} else {
$app->status(400);
echo 'Invalid URL';
}
});