Fetching contributors…
Cannot retrieve contributors at this time
50 lines (40 sloc) 1.18 KB

ONE PHP Micro Framework Documentation


Action on GET Request:

//index.php file
$app = new \OnePHP\App();

$app->get('/',function() use ($app){//Action
    echo 'Hello world';

Action on POST Request with slugs: (same with PUT and DELETE)

Slugs are defined by {x} or :x inside a Route


//$id_book will be the value passed on the URL
$app->put('/book/:id_book/',function($id_book) use ($app){

$app->delete('/book/{id_book}/',function($id_book) use ($app){

Respond all Request (if no match)

$app->respond( function() use ( $app ){
    return $app->ResponseHTML('<p> This is a response with code 404. </p>', 404);

Generating new routes with getRoute

<a href="<?php echo $app->generateRoute('/about'); ?>"> About </a>

<a href="<?php echo $app->generateRoute('/book/'.$id_book.'/edit'); ?>">
    Edit $book

Next: Controllers

Contribute and improve this documentation.
Click Edit and Fork the project.