PHP code example of tkaratug / titan-router

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

    

tkaratug / titan-router example snippets




use Titan\Router\Router as Route;

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

Route::execute();

Route::get('pattern', function() { /* ... */ });
Route::post('pattern', function() { /* ... */ });
Route::put('pattern', function() { /* ... */ });
Route::delete('pattern', function() { /* ... */ });
Route::options('pattern', function() { /* ... */ });
Route::patch('pattern', function() { /* ... */ });

Route::get('/profile', 'User@viewProfile'); // Without namespace
Route::get('/product/{num}', 'App\Controllers\Product@detail'); // With namespace

Route::middleware(['auth'])->group(function(){
    Route::get('/dashboard', function(){ /* ... */} );
});

Route::namespace('backend')->group(function(){
    // Controllers Within The "Controllers\Backend" Namespace
});

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

Route::domain('api.example.com')->group(function(){
    Route::get('user/{num}', function($id){
        //
    });
});

Route::namespace('backend')->prefix('admin')->middleware(['auth'])->group(function(){
    Route::get('/', 'Dashboard@index');
    // Controller = Controllers\Backend\Dashboard
    // URL = /admin
    // Middleware = Auth
});

Route::set404(function() {
    header('HTTP/1.1 404 Not Found');
    // ... do something special here
});