forked from juliomatcom/one-php-microframework
/
index.php
31 lines (25 loc) · 901 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
//One Micro Framework - Hello World
//remember enable the .htacess in this folder
require_once('src/OnePHP/one_framework.php');
/*
* Remember remove this examples to avoid collisions in routes
*/
//load Micro Framework with debug enabled
$app = new \OnePHP\App();
$app->get('/', function() use ( $app ){//Action on the Root URL
echo 'Hello world';
});
//test with slug in URL ( ':name' = '{name}' )
$app->get('/:name', function( $name ) use ( $app ){
echo "<h1> Hello <small> $name </small> </h1>";
});
//simple Json Response example
$app->get('/json/:name', function( $name ) use ( $app ){
return $app->JsonResponse(array('name' => $name));
});
$app->respond( function() use ( $app ){
return $app->ResponseHTML('<p> This is a response with code 404. </p>', 404);
});
//Run
$app->listen();