PHP code example of artkoder / peasy-router

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

    

artkoder / peasy-router example snippets


// public/index.php
\Http\Router;

// You need to pass the path to your routes directory
$router = new Router('/path/to/routes/directory');

$router->handleRequest();

// web.php
return [
    [
        'name' => 'budget-report',
        'path' => '/budget/{start}/{end}',
        'method' => 'get',
        'controller' => 'ArtKoder\Peasy\Controllers\Budget::report'
    ],
    [
        'name' => 'budget-index',
        'path' => '/budget',
        'method' => 'get',
        'controller' => 'ArtKoder\Peasy\Controllers\Budget::index'
    ]
];


// src/Controllers/Budget.php

namespace ArtKoder\Peasy\Controllers;

class Budget 
{
    public static function report($start, $end)
    {
        echo "start: $start\n";
        echo "end: $end\n";
    }

    public static function index()
    {
        echo "Budget index\n";
    }
}

// src/Controllers/Budget.php

namespace ArtKoder\Peasy\Controllers;

class Budget 
{
    public static function report($start, $end, $var = '')
    {
        echo "start: $start\n";
        echo "end: $end\n";
        echo "var: $var\n";
    }

    public static function index()
    {
        echo "Budget index\n";
    }
}