PHP code example of webhoanhao / simple-router

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

    

webhoanhao / simple-router example snippets


// code in: ./public/index.php

// Require the router class
 project)
pp namespace (change namespace to match your project)
use App\Controllers\HomeController;

// Add your routes
Route::add('/', HomeController::class,'index','index-route-name');
Route::add('/hello', HomeController::class,'hello','hello-route-name');
Route::add('/product-detail', ProductController::class,'detail','product-detail');
// ....

// Run the router
Route::run();

// code in: ./public/index.php

// Autoload files using composer
Use app namespace (change namespace to match your project)
use App\Controllers\HomeController;

// Add your routes
Route::add('/', HomeController::class,'index','index-route-name');
Route::add('/hello', HomeController::class,'hello','hello-route-name');
Route::add('/product-detail', ProductController::class,'detail','product-detail');
// ....

// Run the router
Route::run();

$url = Route::url('routeName');

$url = Route::url('routeName',[$param_1,2,'param3']);

    public function detail($param1, $param2, $param3)
    {
        echo "Param1 = ".$param1;
        echo "Param2 = ".$param2;
        echo "Param3 = ".$param3;
    }