PHP code example of veka-server / rooter

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

    

veka-server / rooter example snippets


// Creation de l'objet
$router = new \VekaServer\Rooter\Rooter();

// Définir une page 404
$router->set404(function(){
    echo 'ma page 404';
});


$router->get(
    '/connexion/magasin/([a-zA-Z0-9_\-+ ]+)/'
    , function($magasin) {
        $obj = new connexion_controller(true);
        $obj->connexion($magasin);
    }
);

$router->get(
    '/home'
    , ['maClasse', 'maMethode']
);

$router->get('/home', ['maClasse', 'maMethode']);
$router->post('/home', ['maClasse', 'maMethode']);
$router->getAndPost('/home', ['maClasse', 'maMethode']);
$router->put('/home', ['maClasse', 'maMethode']);
$router->delete('/home', ['maClasse', 'maMethode']);
$router->head('/home', ['maClasse', 'maMethode']);
$router->option('/home', ['maClasse', 'maMethode']);
$router->trace('/home', ['maClasse', 'maMethode']);
$router->connect('/home', ['maClasse', 'maMethode']);

$router->dispatchGlobal();

// creation du dispatcher
$Dispatcher = new VekaServer\Dispatcher\Dispatcher();

// creer le router
$router = new VekaServer\Rooter\Rooter();

// Définir une page 404
$router->set404(function(){
    echo 'ma page 404';
});

// ajouter les route ici, par exemple
$router->get('/home', ['maClasse', 'maMethode']);

// ajout le middlewares
$Dispatcher->pipe($router);