PHP code example of np / router

1. Go to this page and download the library: Download np/router 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/ */

    

np / router example snippets




use np\router;

$route = new router;

$route->get('/',function(){
     	echo 'GET method';
});
$route->post('/',function(){
	echo 'POST method';
});
$route->put('/',function(){
	echo 'PUT method';
});
$route->patch('/',function(){
	echo 'PATCH method';
});
$route->delete('/',function(){
	echo 'DELETE method';
});
$route->option('/',function(){
	echo 'OPTION method';
});

$route->get('/post/{id}',function($data){
	echo 'This is post page and id = '.$data['id'];
});

function loadView($view){
	echo file_get_contents($view);
}
$route->get('/',function(){
	loadView('./dir_name');
});

$route->listen();

$route->setCallbackError(function(){
	loadView('./404.php');
});