PHP code example of alexkratky / routex

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

    

alexkratky / routex example snippets




use AlexKratky\URL;
use AlexKratky\Route;
use AlexKratky\RouteHandler;

Route::setError(Route::ERROR_NOT_FOUND, "404.php"); // only if you want custom error 404 page
Route::set('/', 'home.php'); // set routes - URI: '/', template file: 'home.php'

$URL = new URL(); // Creates a new instance of URL object
Route::setMiddlewaresPath($_SERVER['DOCUMENT_ROOT'] . '/middlewares/'); // only if you will use middlewares
Route::setControllersPath($_SERVER['DOCUMENT_ROOT'] . '/controllers/'); // optional (faster improvement)
$template_files = Route::search($URL->getString()); // Searches in all routes and find the right template file

$rh = new RouteHandler($_SERVER['DOCUMENT_ROOT'] . '/template/', $_SERVER['DOCUMENT_ROOT'] . '/controllers/', $_SERVER['DOCUMENT_ROOT'] . '/handlers/'); // *
$rh->setHandlers([
    'latte' => 'LatteHandler'
]); // Sets custom handler for *.latte extension
$rh->handle($template_files); // 

Route::set("/URI/TO/HANDLE", "File_to_

Route::setError(404, "default/errors/404.php");
 

Route::set("/", "home.php");
Route::set("*", "test.php");

Route::set("*", "test.php");
Route::set("/", "home.php");

 Route::set("/admin/<controller>/<action>", "form.php");

Route::set("example/{ID[^[0-9]*$]}", "id.php");

Route::set("/{NAME#Validator::validateUsername}");

Route::set("/docs/intro", ["header.php", "intro.php", "footer.php"]);

Route::set("/docs", function() {
    redirect("/docs/intro");
});
Route::set("/docs/intro", ["header.php", "intro.php", "footer.php"]);

Route::set("/dumpServerVariable", function() {
    echo 'This route will dump() $_SERVER variable';
    dump($_SERVER); // Function from panx
});

Route::set("/", "home.php", ["GET"]);

Route::set("/postGet", "example.php", ["POST", "GET"]);

Route::apiGroup("v1", array(
    // /api/v1/list
    array("list", function(){
        echo "list";
    }),
    // /api/v1/getlatestversion/stable
    array("getlatestversion/stable", function() {
        echo "0.1";
    }, ["GET"]),
));

Route::set('/login', 'auth/login.latte')->setController("AuthController");
 

Route::set('/verifymail/{TOKEN}', function() {
    
})->setMiddleware(['AuthMiddleware']);

Route::setApiEndpoint("v3", new API("v3"));

Route::apiGroup("v5", array(
    array(
        "route" => "test/{name}/{action}",
        "files" => null,
        "lock" => null,
        "
+HTML

Route::set("/test/of/route/<action>/{NAME}/{ID}/*", function() {echo "Hello";});