1. Go to this page and download the library: Download xiaozhuangyuan/srouter 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/ */
Srouter::get('/(:any)', function($slug) {
echo 'The slug is: ' . $slug;
});
Srouter::dispatch();
Srouter::get('/', function() {
echo 'I'm a GET request!';
});
Srouter::post('/', function() {
echo 'I'm a POST request!';
});
Srouter::map(['get','post'],'/', function() {
echo 'I can be both a GET and a POST request!';
});
Srouter::any('/', function() {
echo 'I can be any request!';
});
Srouter::dispatch();
Srouter::error(function() {
echo '404 :: Not Found';
});
use Xiaozhuangyuan\Srouter\Srouter;
Srouter::get('/', 'controllers\Test@index');
Srouter::get('page', 'controllers\Test@page');
Srouter::get('view/(:num)', 'controllers\Test@view');
Srouter::dispatch();
namespace controllers;
class Test {
public function index()
{
echo 'home';
}
public function page()
{
echo 'page';
}
public function view($id)
{
echo $id;
}
}
use Xiaozhuangyuan\Srouter\Router;
$router = new Router();
$router->group('/v1', function () use ($router) {
$router->group('', function () use($router) {
$router->get('', 'app\controllers\Demo@index', ['Check']);
});
$router->any('/nasad', 'app\controllers\Demo@index');
$router->map(['get', 'post'], '/page', 'app\controllers\Demo@page');
$router->get('/view/(:num)', 'app\controllers\Demo@view');
$router->get('/pi', 'app\controllers\Demo@pi');
$router->get('/db', 'app\controllers\Demo@db');
$router->get('/log', 'app\controllers\Demo@log');
$router->get('/cache', 'app\controllers\Demo@cache');
$router->group('/user', function ($router) {
$router->get('/info', 'app\controllers\Demo@index');
$router->group('/user122', function ($router) {
$router->get('/info', 'app\controllers\Demo@index');
}, ['PK']);
}, ['Check']);
$router->get('/qwwasas', 'app\controllers\Sms@qwqw');
}, ['Auth']);
$router->dispatch();
namespace app\controllers;
class Test {
public function index()
{
echo 'home';
}
public function page()
{
echo 'page';
}
public function view($id)
{
echo $id;
}
}
namespace app\middleware;
use Xiaozhuangyuan\Srouter\Middleware;
class Auth implements Middleware
{
public function handle()
{
return true;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.