PHP code example of struktal / struktal-router

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

    

struktal / struktal-router example snippets


\struktal\Router\Router::setPagesDirectory("path/to/your/pages");
\struktal\Router\Router::setAppUrl("https://yourdomain.com");
\struktal\Router\Router::setAppBaseUri("/"); // Or if you want to use a subdirectory, e.g. "/your-app/"
\struktal\Router\Router::setStaticDirectoryUri("static/");

\struktal\Router\Router::addRoute(
    "GET",
    "/",
    "index.php",
    "index"
);

\struktal\Router\Router::addRoute(
    "GET",
    "/user/{i:userId}",
    "users/details.php",
    "user_details"
);

$userId = $_GET['userId'];

\struktal\Router\Router::addRoute(
    "GET|POST"
    "/user",
    "user.php",
    "user"
);

\struktal\Router\Router::setError400Route(\strukral\Router\Router::generate("400"));
\struktal\Router\Router::setError404Route(\struktal\Router\Router::generate("404"));

$router = new \struktal\Router\Router();
$router->startRouter();

$url = \struktal\Router\Router::generate("user_details", ["userId" => 42]);

$staticFilePath = \struktal\Router\Router::staticFilePath("css/style.css");