PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Stefano Azzolini   mu   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: mu
Handle HTTP requests using callback functions
Author: By
Last change:
Date: 21 days ago
Size: 796 bytes
 

Contents

Class file image Download
<?php

/**
 * µ PHP microframework
 *
 * @author Stefano Azzolini <lastguest@gmail.com>
 */


include 'mu.php';

/**
*
* Define routes callbacks with this syntax :
* µ::METHOD('ROUTE',CALLBACK);
*
* - METHOD can be GET,POST,PUT,DELETE,HEAD or some custom HTTP verb
* - ROUTE is the URL path fragment
* - CALLBACK is a callable object () invoked by the router.
*/


µ::GET('/',function(){
    echo
'What is your name?';
    echo
'<form method=post><input type=text name=username><input type=submit></form>';
});

/**
* This is executed only when the browser call a POST on '/' route
*/

µ::POST('/',function(){
    echo
'Hello ',$_POST['username'],', how are you?';
});


/**
* Invoke the phpinfo function on /php/info route
*/

µ::GET('/php/info','phpinfo');


/**
* Run the application
*/

µ::_();