PHP code example of zhukmax / simple-router

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

    

zhukmax / simple-router example snippets




rojectName\API\Controllers\IndexController;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Zhukmax\Waymark\Router;

/** Add Twig Template engine **/
$loader = new FilesystemLoader(__DIR__ . '/src/views');
$twig = new Environment($loader);

(new Router([
    'tplEngine' => $twig,
    'namespace' => '\\ProjectName\\API\\Controllers',
    'routes' => dirname(__FILE__).'/routes.json'
]))
    ->get('/api/users', IndexController::class, 'actionGetAll', 'json')
    ->output();



namespace ProjectName\API\Controllers;

use Zhukmax\Waymark\AbstractController;
use Zhukmax\Waymark\Request;

class IndexController extends AbstractController
{
    public static function actionGetAll()
    {
        $date = Request::get('date');
        $page = Request::getInt('page', 0);
        
        return [
            'date' => $date,
            'page'=> $page
        ];
    }

    public function tst(string $date, int $page)
    {
        return $this->tpl->render('index.twig', [
            'date' => $date,
            'page' => $page
        ]);
    }
}