PHP code example of caichuanhai / router

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

    

caichuanhai / router example snippets



//或

use caichuanhai\router;
Router::get('a', controller@method);
//或
caichuanhai\Router::get('a', controller@method);

Router::get('hello', function () {
    return 'Hello, Welcome to my world';
});

Route::get($uri, controller@method);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Route::any($uri, $callback); /*匹配任意HTTP请求动作*/

Router::get('c/caichuanhai', function (){
	...code
});

Router::post('a/b/(:num)', 'a@bpost')

Router::post('a/b/[0-9]+', 'a@bpost')

$cch = new a();
$cch->$bpost(2, 3)

Route::get('user/profile', 'UserController@showProfile')->name('profile');

Router::redirect('profile', [$param]);

Router::prefix('cai')->name('cch.')->group(function (){
	Router::any('e/f', 'e@f')->name('123');
	Router::any('g/[0-9]', 'e@f')->name('hai');

});

Route::prefix('admin')->group(function () {
    Route::get('users', function () {
        // Matches The "/admin/users" URL
    });
});

Route::name('admin.')->group(function () {
    Route::get('users', function () {
        // 新的路由名称为 "admin.users"...
    })->name('users');
});

Router::setDefaultRoute('cai@chuanhai');

Router::set404Route('cai@chuanhai404');

Router::redirect404();

Router::run($conpath);