PHP code example of cdyun / php-router

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

    

cdyun / php-router example snippets


use Cdyun\PhpRouter\Route;

Route::get('/', function() {
  echo 'Hello world!';
});

Route::get('/(:any)', function($arg) {
  echo '传参: ' . $arg;
});

Route::dispatch();

Route::get('/', function() {
  echo 'GET请求';
});

Route::post('/', function() {
  echo 'POST请求';
});

Route::any('/', function() {
  echo 'GET/POST请求';
});

Route::dispatch();

Route::error(function() {
  echo '404 :: Not Found';
});



use Cdyun\PhpRouter\Route;

Route::get('/', 'Controllers\demo@index');
Route::get('page', 'Controllers\demo@page');
Route::get('view/(:num)', 'Controllers\demo@view');

Route::dispatch();


namespace Controllers;

class Demo {

    public function index()
    {
        echo 'home';
    }

    public function page()
    {
        echo 'page';
    }

    public function view($id)
    {
        echo $id;
    }

}

composer