PHP code example of fhooe / router

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

    

fhooe / router example snippets


   $router = new Router();
   

   $router->get("/", function() {
       // e.g., load a view
   });
   

   $router->set404Callback(function() {
       // e.g., load a 404 view
   });
   

   $router->setBasePath("/path/to/your/files");
   

   $router->run();
   

   $route = Router::getRoute("/path/to/your/files");
   

   switch($route) {
       case "GET /":
           // e.g., load a view
           break;
       default:
           // e.g., load the 404 view
           break;
   }