1. Go to this page and download the library: Download zkrati/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/ */
zkrati / router example snippets
$router = new Zkrati\Routing\SimpleRouter();
$router->get("/test", function() {
// handle GET request at /test
});
$router->post("/test", function() {
// handle POST request at /test
});
$router->run();
$router->get("/test/path", "Class:methodName");
// this code will create an instance of Class and call it's method methodName
$router->get("/test/path", "Namespace\Class:methodName");
// if you are using namespaces
$instance = new Class();
$router->get("/testuju/path", array($instance, "methodName"));
// this code will use the given instance of Class and call it's method methodName
$router->get("/test/<variable>/<next_variable>/path", function($variables) {
// variables <variable> and <next_variable> are available in array $variables by it's keys
// for example with url /test/example/showcase/path
echo $variables["variable"]; // will output "example"
echo $variables["next_variable"]; // will output "showcase"
});
$router->get("/test/path/*", "Class:methodName");
// this code will match all paths starting /test/path/ for example:
// - /test/path/first
// - /test/path/second
// - /test/path/every/other/path
$router->option("*", "Class:methodName");
// This will handle all option requests
$router->setInstantiator($instantiator, "getInstance");
// where $instantiator is your custom instantiator and "getInstance" is name of it´s method to get instance
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.