PHP code example of bistro / router

1. Go to this page and download the library: Download bistro/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/ */

    

bistro / router example snippets

 php
$router = new \Bistro\Router\Router;
$router->add('home', '/')->defaults(array(
	'controller' => 'welcome',
	'action' => 'view'
));
 php
$method = $_SERVER['REQUEST_METHOD'];
$uri = isset($_SEVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';

$params = $router->match($method, $uri);
// $params = array('controller' => 'welcome', 'action' => 'view');
 php
$router->add('crud', '/:controller/:action/:id?')->defaults(array(
	'id' => null
));
 php
$router->add('id_only', '/:controller/user|post:action/\d+:id');
 php
$router->post('login', '/login')->defaults(array('controller' => 'login', 'action' => 'process'));
 php
$router->add('wildcard', '/:controller/.*:wildcard')
 php
$router->add('api', "/:controller/\d+:id?")
	->get(array('action' => 'read'))
	->post(array('action' => 'create'))
	->put(array('action' => 'update'))
	->delete(array('action' => 'delete'));
 php
$router->add('reverse', '/blog/:year/:month/:day');

// Reverse Routing magic!
echo $router->url('reverse', array(
	'year' => 2013,
	'month' => 03,
	'day' => 31
));
// Output: /blog/2013/03/31
 php
$router = new \Bistro\Router\Router('subdirectory');