PHP code example of rgehan / router

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

    

rgehan / router example snippets




// Requires the Composer autoloader, allowing us to use external modules
ook for controllers
Router::setControllerNamespace('\\rgehan\\myProject\\controllers\\');

// Sets the variables that will be passed to all controllers methods
Router::setRoutesGlobalParameters(['global variable 1', 123, [1, 2, 3]]);

// Defines the routes
Router::get('/', 'HomeController@index');
Router::get('/home', 'HomeController@index');
Router::get('/articles', 'ArticlesController@index');
Router::get('/article', 'ArticlesController@get');

Router::post('/search/name', 'ArticlesController@search');

Router::delete('/article', 'ArticlesController@delete');

Router::update('/article', 'ArticlesController@delete');

// Dispatch the current request to the correct controller/method
Router::dispatch();