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', '/report', function ($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 ($app, $params) {
var_dump($params);
});
array(2) {
["user"]=>
string(3) "mary"
}
$app->action('GET', '/article/<name>-<id>', function ($app, $params) {
// Only numeric IDs are valid
if (ctype_digit($params['id'])) {
echo 'Article ID: ', $params['id'], '<br>';
echo 'Article name: ', $params['name'];
} else {
$app->status(400);
echo 'Invalid URL';
}
});
bat
rem Setup PHP, php.ini and variable order
set PHP_BIN=C:\php\php.exe
set PHP_INI=C:\php\php.ini
set PHP_VAR=GPCS
rem Setup host and port
set HOST_ADDR=localhost
set HOST_PORT=9000
sh
# Setup PHP, php.ini and variable order
PHP_BIN=/usr/bin/php
PHP_INI=/etc/php.ini
PHP_VAR=EGPCS
# Setup host and port
HOST_ADDR=localhost
HOST_PORT=9000