PHP code example of brdev / router

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

    

brdev / router example snippets





use BRdev\Router\Router;
use BRdev\Router\Web\Web;

::get('/','Web@home');
//or
Router::get('/',[Web::class,'web']);

Router::get('/sobre','Web@about');

//namespace
Router::namespace("BRdev\Router\App");
Router::get('/user/{id}', 'App@user');

Router::group('/error');
Router::get('/{code}','App@error');
Router::endgroup();

Router::dispatch();

//error
if(Router::error()){
    Router::redirect("/error/".Router::getError());
}





use BRdev\Router\Router;


    echo "Pagina Home";
});

Router::get('/sobre', function () {
    echo "Pagina Sobre";
});

Router::get('/user/{id}', function ($data) {
    echo "User ". $data->id;
});

Router::group('/error');
    Router::get('/{code}',function ($data){
        var_dump($data->code)
    });
Router::endgroup();

Router::dispatch();

//error
if(Router::error()){
    Router::redirect("/error/".Router::getError());
}

`nginxconfig
location / {
     try_files $uri $uri/ /index.php?route=$uri&$args;
}