Router
Q&A
Introduction:how does router work and what goal is this component for?
A=>make URL shorter and friendly as well as better user experience.(customize URL)
1.static page
(/config/Route.php)
$routes->add('parameter01','parameter02');
//parameter01:url segment
//parameter02:corresponding controller and method inside the controller
Another way to accomplish it:
$routes->add(' segment name ' , function(){});
2.static page with multiple parameters
(/config/Route.php) Taking two parameters for example
$routes->add('parameter01/(:any)/(:any)','parameter02/$1/$2');
//parameter01:url segment
//parameter02:corresponding controller and method inside the controller
//Only discuss on the basic example
3.access files inside one private folder or lie in inferior level below controller
/mall/shop/check/1/2
$routes->group( 'mall',function($routes){
$routes->add('shop/(:any)/(:any)','check/$1/$2');
});
4.same URL doing different jobs
via get and post method
$routes->get('parameter1','parameter2');
$routes->post('parameter1','parameter2');
//parameter description is as same as above.