PHP code example of drips / routing

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

    

drips / routing example snippets



use Drips\Routing\Router;

$router = Router::getInstance();


$router->add("name_der_route", "/my/url", function(){
    echo "Hello World!";
});

$router->add("name_der_route", "/my/url", MyController::class);


$router->add("name_der_route", "/my/url/{name}", function($name){
    echo "Hello $name!";
});


$router->add("name_der_route", "/my/url/{name}", function($name){
    echo "Hello $name!";
}, array(
    "pattern" => array(
        "name" => "([A-Za-z]+)"
    );
));


$router->add("name_der_route", "/my/url", function(){
    echo "Hello World!";
}, array(
    "https" => true,
    "verb" => ["POST", "GET"],
    "domain" => ["example.com", "example.at"]
));


$router->route();


if($router->hasRoutes()){
	// Es sind bereits Routen registriert
} else {
	// Es sind noch keine Routen registriert
}


$routes = $router->getRoutes(); // returns array


try {
    $router->route();
} catch(Error404Exception $e) {
    echo "Error 404 - Die Seite wurde nicht gefunden!";
}


$url = route("testRoute");


$url = route("users", array("username" => "admin"));


$url = asset("css/style.css");


redirect("home");
apacheconf
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA]
</IfModule>