1. Go to this page and download the library: Download ngyuki/route-collector 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/ */
ngyuki / route-collector example snippets
$registry = new RouteRegistry();
$r = new RouteCollector($registry);
// GET / -> HomeController::index
$r->path('/')->get()->controller('HomeController')->action('index');
// GET|POST /both -> HomeController::both
$r->path('/both')->get()->post()->controller('HomeController')->action('both');
// GET|POST /both -> HomeController::method
$r->path('/method')->method('GET|POST')->controller('HomeController')->action('method');
$r->controller('UserController')->group(function (RouteCollector $r) {
$r->path('/user')->group(function (RouteCollector $r) {
// GET /user -> UserController::index
$r->get()->action('index');
// GET /user/create -> UserController::create
$r->path('/create')->get()->action('create');
// POST /user/create -> UserController::store
$r->path('/create')->post()->action('store');
});
$r->path('/user/{id}')->group(function (RouteCollector $r) {
// GET /user/{id} -> UserController::show
$r->get()->action('show');
// GET /user/{id}/edit -> UserController::edit
$r->path('/edit')->get()->action('edit');
// PUT /user/{id}/edit -> UserController::update
$r->path('/edit')->put()->action('update');
// DELETE /user/{id}/edit -> UserController::delete
$r->path('/edit')->delete()->action('delete');
});
});
return $registry->getRoutes();