PHP code example of luthier / framework
1. Go to this page and download the library: Download luthier/framework 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/ */
luthier / framework example snippets
# your_app/index.php
);
$app->get('/', function(){
$this->response->write("Hello world!");
});
$app->group('api', function(){
$this->get('/', function(){
json_response(['message' => 'Welcome to Luthier Framework!']);
});
$this->get('about', function(){
json_response(['version' => Luthier\Framework::VERSION]);
});
});
$app->run();
$app->get('foo/', function(){
// Default template engine (will search for /foo.php file)
view('foo');
});
$app->post('bar/', function(){
view('bar');
});
$app->match(['get','post'], 'baz/', function(){
view('baz');
});
$app->get('hello/{name}', function($name){
$this->response->write("Hello $name!");
});
// Optional parameters
$app->get('about/{category?}', function($category = 'animals'){
$this->response->write("Category: category");
});
// Regex parameters
$app->get('website/{((en|es|fr)):lang}', function($lang){
$this->response->write($lang);
});
// Global middleware:
$app->middleware(function($request, $response, $next){
$response->write('Global <br>');
$next($request, $response);
});
// Global middleware (but not assigned to any route yet)
$app->middleware('test', function($request, $response, $next){
$response->write('Before route<br>');
$next($request, $response);
$response->write('After route <br>');
});
$this->get('/', function(){
$this->response->write('Route <br>')
})->middleware('test'); // <- assign the 'test' middleware to this route