PHP code example of sevencoder / router

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

    

sevencoder / router example snippets




evenCoder\Router\Router;

/* this is the separator of class and method(of class controller) */
$separator = '@';

/* this is project url, you can define it here or get it from elsewhere */
$projectUrl = 'http://localhost/router';

$router = new Router($projectUrl, $separator);

/* base directory that get controller */
$baseDir = __DIR__.'/App/Controller';

/* set the base controller */
$router->setBasePath($baseDir);

$router->get('/', 'HomeController@helloWorld');
$router->get('test/{teste}/{teste2}', 'HomeController@testGet');
$router->post('test-post', 'HomeController@testPost');
$router->put('test-put', 'HomeController@testPut');
$router->patch('test-patch', 'HomeController@testPatch');
$router->options('test-options', 'HomeController@testOptions');
$router->delete('test-delete', 'HomeController@testDelete');

$router->prefix('test-prefix');
$router->get('1/{param1}/{param2}', 'HomeController@testGestPrefix');
$router->get('2', 'HomeController@testGetPrefix');

$router->dispatch();