PHP code example of onesimus-systems / osrouter

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

    

onesimus-systems / osrouter example snippets


use \Onesimus\Router\Router;
use \Onesimus\Router\Http\Request;

// First we add some routes
// The root path is sent to the index method of the HomeController class
Router::get('/', 'HomeController@index');
// Any path with a page such as /dash, /admin, etc
Router::get('/{page}', 'RenderController@render');
// API, oute = Router::route($request);
// Dispatch route
// Execute the closure or the class/method combo
$route->dispatch();

// You can also pass an argument to the called closure
// or the class being instantiated
$route->dispatch($app);

Router::group(['prefix' => '/admin'],
	['get', '/groups/{?id}', 'Controller@groups'],
	['get', '/users/{?id}', 'Controller@user']
);

// First register filter
// This function will return true if the session is authenticated
// or false otherwise. You may want to do some sort of redirect here
// as well for a failed authentication for example to a login page.
Router::filter('auth', function() {
    return is_authenticated();
});

// Define route for '/admin' path with filter of 'auth'
Router::get('/admin', 'AdminController@index', 'auth');

Router::get('/admin', 'AdminController@index', ['auth', 'inAdminGroup']);