PHP code example of saaiph / router

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

    

saaiph / router example snippets


    use \Saaiph\Router\Router;

    //$filename é o local onde vai ficar armazenado os verbos usados no http padrão, GET, POST, PUT e Delete;
    //$namespaceController argumentos opcional, se for usar controllers no seus projeto é necessário colocar o namespace inicial onde ficarar armazenado o seus controllers;
    $router = new Router($filename, true or false, $namespace_controller);

    //Exemplo de uso
    $router = new Router(__DIR__."/router/web.php", true, "\Controllers\\");

//Instanciando o verbos
    Use \Saaiph\Router\Router;

    //Verbos
    Router::get($url, $struct);
    Router::post($url, $struct);
    Router::put($url, $struct);
    Router::delete($url, $struct);

    //Verbos utilizando function
    Router::get("/home", function () {
        #Código
    });
    Router::post("/home", function () {
        #Código
    });
    Router::put("/home", function () {
        #Código
    });
    Router::delete("/home", function () {
        #Código
    });

    //Verbos utilizando Controllers;
    Router::get("/home", "Controller@action");
    Router::post("/home", "Controller@action");
    Router::put("/home", "Controller@action");
    Router::delete("/home", "Controller@action");