PHP code example of dongnan / microrouter

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

    

dongnan / microrouter example snippets



er = new \MicroRouter\Router();

$router->respond('GET', '/hello-world', function () {
    return 'Hello World!';
});

$router->dispatch();


$router->respond('/hello-world', function () {
    return 'Hello World!';
});


$router->respond('/[:name]', function ($params) {
    return 'Hello ' . $params['name'];
});


$router->respond('GET', '/users', $callback);
$router->respond('POST', '/users', $callback);
$router->respond('PUT', '/users/[i:id]', $callback);
$router->respond('DELETE', '/users/[i:id]', $callback);
//匹配多个请求
$router->respond(array('GET','POST'), '/path', $callback);

 
	//引入 MicroRouter 的自动加载文件
	
nginx
location / {
  try_files $uri $uri/ /index.php?$args;
}