PHP code example of lablnet / zestrouter

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

    

lablnet / zestrouter example snippets


 

use Lablnet\ZestRouter;

mespaces uses for loading controllers olny
//$router->setDefaultNamespace("App\Controllers\\");

$router->get('', function () {
    echo 'Example route using closure';
});
/*
//OR
$router->add('', function () {
    echo 'Example route using closure';
},'GET');
*/
$router->get('test','Home@index');
/*
 //OR
 $router->get('test',['controller' => 'Home', 'action' => 'index']);
 //OR
  $router->add('test',['controller' => 'Home', 'action' => 'index'],'GET');

*/
//Dispatch/Process the request automatically for mannually dispatch request take a look at Process Request section
$router->dispatch($_SERVER['QUERY_STRING']);



    $router->add('', function () {
        echo "Welcome";
    },'GET'); 



    $router->get('', function () {
        echo "Welcome";
    }); 



// add homepage using callable
$router->get( '/home', function() {
    get( 'users/{id:[0-9]+}', 'UserController@showDetails' );


$router->addRoutes(array(
  array('users/{username:\w+}', 'users@view', 'get'),
  array('users/{id:\d+}', 'users@update', 'PATCH'),
  array('users/{id:\d+}', 'users@delete', 'DELETE')
));
 

//Add the routes
$router->get('', function () {
    echo 'Example route using closure';
});
$router->get('user/{id:\d+}', function ($args) {
    echo 'Example route using closure with params id: ' .$args['id'];
});

// match current request url
$match = $router->customDispatch();
if ($match && is_callable( $match['callable'] )) {
	call_user_func( $match['callable'], $match ); 
} else {
	// no route was matched
	echo '404 Not Found';
}



location / { 
    if (!-f $request_filename){
        set $rule_0 1$rule_0;
    }   
    if (!-d $request_filename){
        set $rule_0 2$rule_0;
    }
    if ($rule_0 = "21"){
        rewrite ^/(.*)$ /index.php?$1 last;
    }   
}

 php
$match = $router->customDispatch();