PHP code example of phoenix-code21 / firecore-router

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

    

phoenix-code21 / firecore-router example snippets

bash
use Firecore\Router\Router;

$router = new Router;

// Base opcional (ex: subdiretório)
$router->setBasePath('/meu-projeto');

// Rota GET simples
$router->get('/', function () {
    echo 'Página inicial';
});

// Rota com parâmetros
$router->get('/user/{id}', function ($id) {
    echo "Usuário: {$id}";
});

// Rotas com grupo e namespace
$router->namespace('App\\Controllers');
$router->group('/admin', function ($router) {
    $router->get('/dashboard', 'DashboardController@index');
});

// Middlewares
$router->middleware('App\\Middleware\\Auth@handle')
       ->get('/painel', function () {
           echo 'Área protegida';
       });

// Erro 404 personalizado
$router->setError('/erro', 404, function () {
    echo 'Página não encontrada';
});

// Executa o roteador
$router->dispatch();