1. Go to this page and download the library: Download sevens/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/ */
sevens / router example snippets
use \Seven\Router\Router;
#namespace: refers to the namespace from which the classes should be loaded
$route = new Router($namespace = 'App\Controllers');
$route->all('/posts', function($request, $response){
return $response->send("This handles all requests to /posts endpoint, regardless of request method");
});
$route->put('/post/:key', function($request, $response){
return $response->send("This is a request containing key: ". $request->params->key )
});
#cors middleware is called first in this case.
$route->use(['middleware' => ['cors', 'auth'],'prefix'=>'api' ], function() use ($route){
$route->get('/post/:id', function($request, $response){
});
# request & response objects are passed as arguments automagically
$route->post('/post', [ PostController::class, 'create' ]);
});
$route->use('cors,auth;prefix:api;', function() use ($route){
$route->get('/post/:id', function($request, $response){
});
# request & response objects are passed as arguments automagically
$route->post('/post', [ PostController::class, 'create' ]);
});
#start with a ';' if no middleware is being used
$route->use(';prefix:api/test;', function() use ($route){
});