PHP code example of bulveyz / router-php
1. Go to this page and download the library: Download bulveyz/router-php 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/ */
bulveyz / router-php example snippets
use BulveyzRouter\Route;
use BulveyzRouter\Router;
Route::get('/home', function() {
echo "Home";
});
Route::any('/user/{id}', function($param) {
echo "User" . $param->id;
});
Route::post('/create/post', 'PostController@store');
Router::routeVoid();
use BulveyzRouter\Router;
// Defained routes
use BulveyzRouter\Route;
Route::get('/home', function() {
echo "Home";
});
Route::get('/user/{id}/{second_id}', function($params) {
echo $params->id . $params->second_id;
});
Route::get('/user/{id}/{second_id}', 'HomeController@index');
public function index($params)
{
echo $params->id . $params->second_id;
}
Route::get('/home', 'HomeController@index')->name('home.index');
echo \route('home.index'); // return '/home'
Route::setNamespace('Your namespace');
"Route::setNamespace('Classes');"
var_dump(Route::routeList());
// Return namespace
echo Route::getNamespace()
// Return path for route
echo \route('routeName');
Route::get('/user', function (){
// Return method this route
echo Router::$method;
// Return path this route
echo Router::$route;
// Return params this route (Array)
var_dump(Router::$params);
// Return handler this route
var_dump(Router::$callback);
});
composer