SmlFrame
Getting started
run composer install
edit the .htaccess file to match your file structure, (*1)
Basic setup
require_once 'vendor/autoload.php';
$app = new Sml\Sml();
# Run the application
$app->run();
ROUTING with request
require_once 'vendor/autoload.php';
$app = new Sml\Sml();
$app::get('/', function(){
echo 'test';
});
# If you want to pass arguments to the function you do this with regEx values
# Supported values are for Strings and Ints
# String and int value
$app::get('/user/(\w+)/(\d+)', function( $string, $int ){
# You can then use the params here
});
# POST
$app::post('/user', function() use( $app ) {
# To get the post request you can do:
# This recives a json encoded body for you, and returns as obj.
# If you want a array you can pass true into the json( true )
$app->request()->json();
# This recives the x-www-form-urlencoded body ( normal POST )
$app->request()->body();
});
# Run the application
$app->run();
Response
To use the response obj you need yo inject $app onto your functions, (*2)
require_once 'vendor/autoload.php';
$app = new Sml\Sml();
$app::get('/', function() use( $app ){
$app->response( 200, "it Works" )->send();
});
# You can also send back json_response by chaining the sendJson method onto the response method.
$app::get('/', function() use( $app ){
$app->response( 200, "it Works" )->sendJson();
});
$app->run();
Changelog
version 0.0.2
- Added support for POST, GET, PUT, DELETE routes
- Added exception class for handling errors
- Added Response obj
- Added Request obj
- Added the use of env file, (*3)
version 0.0.1
- Included simple get Route support., (*4)