1. Go to this page and download the library: Download samueltissot/wp_route 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/ */
samueltissot / wp_route example snippets
WP_Route::get('/flights/', 'listFlights');
WP_Route::get('/buses/', 'listBuses');
WP_Route::post('/flights/{flight}/', 'singleFlight');
WP_Route::put('/flights/{flight}/book/{date}', 'bookFlight');
WP_Route::delete('/flights/{flight}/delete', 'deleteFlight');
WP_Route::any('flights/{flight}', array('Class', 'staticMethod'));
WP_Route::patch('flights/{flight}', array($object, 'method'));
WP_Route::match(['get', 'post'], 'flights/{flight}/confirm', 'confirmFlight');
// if you want to take into account the parameters when doing a path match
WP_Route::get('/flights/', 'listFlights', ["match" => "*"]);
// if you want to match one or more parameters
WP_Route::get('/flights/', 'listFlights', ["match" => ['param2', 'param2', ...]]);
// redirect
WP_Route::redirect('open-google', 'https://google.com', 301);
// close
WP_Route::get('flights/{flight}', function singleFlight(RequestInterface $req) {
$req->pathVariable('flight');
}
use samueltissot\WP_Route\RequestInterface;
// an invocable class
class Controller
{
public function __invoke(RequestInterface $req)
{
// code goes here;
}
}
// or a simple function
function my_super_func(RequestInterface $req) {
// code goes here;
}
// method inside class
class MyAwesomeClass
{
public function wow(RequestInterface $req)
{
// code goes here;
}
}
interface RequestInterface
{
public function uri();
public function method();
public function pathVariables();
public function pathVariable($name);
public function parameters();
public function parameter($name);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.