PHP code example of dsisconeto / ciroute

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

    

dsisconeto / ciroute example snippets


if (ENVIRONMENT == 'development') {             
    DIR__."/application/config/routes.php",
        __DIR__."/application/cache/",
        __DIR__."/application/routes/"
        );
    }

use DSisconeto\Ciroute\Route; 

Route::get('hello-world', 'Hello_word/index');

$route["hello-world"]["GET"] = ["Hello_word");

Route::get($rota, $controler_metodo)]

Route::get('eventos/cadastrar', 'create');
Route::post('eventos/cadastrar', 'store');
Route::get('eventos/:num/editar', 'edit/$1');
Route::put('eventos/:num/editar', 'update/$1');
Route::delete('eventos/:num', 'delete/$1');

$route["eventos/cadastrar"]["GET"]="eventos/create"; 
$route["eventos/cadastrar"]["POST"]="eventos/store"; 
$route["eventos/:num/editar"]["GET"]="eventos/edit/$1"; 
$route["eventos/:num/editar"]["PUT"]="eventos/update/$1"; 
$route["eventos/:num"]["DELETE"]="eventos/delete/$1"; 

function ciroute($name, $arguments = [])
{
    static $routes;
    static $regex = "/\(:([A-Za-z0-9_.-]*)\)/";


    if (!$routes) $routes = {
        throw  new \Exception("O segundo argumento tem que ser um array");
    }

    $count = 0;
    $route = preg_replace_callback($regex, function () use (&$count, $arguments) {

        return ($arguments[$count++]);

    }, $routes[$name]);


    return base_url($route);
}