PHP code example of mosz / simple-router

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

    

mosz / simple-router example snippets


// Require composer autoloader
uter = new mOsz\Router\Router($_SERVER['REQUEST_URI']);

// Add routes
$router->get('path', function(){ ... });

$router->run(); 

$router->get('HelloWorld', function(){ echo "Hello World"; });

$router->get('Homepage', function(){ $controller = new Test\Controller; $controller->index(); });

$router->get('posts/{id}', function($id) { $controller = new Test\Controller; $controller->posts($id); });

$router->get('form', function() { $controller = new Test\Controller; $controller->form(); });

$router->post('form', function() { $controller = new Test\Controller; $controller->form(); });