PHP code example of delight-im / router

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

    

delight-im / router example snippets


     

      $router = new \Delight\Router\Router();
      

      $router = new \Delight\Router\Router('/my/base/path');
      

      $router->get('/', function () {
          // do something
      });
      

      $router->get('/users/:id/photo', function ($id) {
          // get the photo for user `$id`
      });
      

      $router->any([ 'POST', 'PUT' ], '/users/:id/address', function ($id) {
          // update the address for user `$id`
      });
      

    // use static methods
    $router->get('/photos/:id/convert/:mode', [ 'PhotoController', 'myStaticMethod' ]);

    // or

    // instance methods
    $router->get('/photos/:id/convert/:mode', [ $myPhotoController, 'myInstanceMethod' ]);
    

    class MyController {

        public static function someStaticMethod($database, $uuid) {
            // do something
        }

    }
    

    $database = new MyDatabase();

    // ...

    $router->delete('/messages/:uuid', [ 'MyController', 'someStaticMethod' ], [ $database ]);
    

      try_files $uri /index.php;