Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
Version : 1.0.0
- Installation
- Simple Usage
- Available Router Methods
- Route Parameters
- Controller and Method Parameters
- Regular Expression Constraints
- Named Routes
- Route Groups
- License
You can download it and using it without any changes.
OR use Composer.
It's recommended that you use Composer to install Route.
$ composer require eylmz/router
Options -Indexes
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
<?php
require 'vendor/autoload.php';
// or
// require 'src/eylmz/Router.php';
use eylmz/Router/Router;
Router::setControllerNamespace("App\\Controllers\\");
Router::setMiddlewareNamespace("App\\Middlewares\\");
// Routers
Router::any("/url","Controller@Method");
// or
Router::any("/url2",function() {
});
// #Routers
Router::routeNow(@$_GET["url"]);
Router::get($url, $callback);
Router::post($url, $callback);
Router::put($url, $callback);
Router::patch($url, $callback);
Router::delete($url, $callback);
Router::options($url, $callback);
Router::match("GET|POST",$url,$callback);
//or
Router::match(["GET","POST"],$url,$callback);
Router::any($url,$callback);
Router::get("url\{id}",function($myID){
echo "Hello " . $myID;
});
Router::get("url\{id?}",function($myID=0){
echo $myID;
});
// Controller -> First Parameter
// Method -> Second Parameter
Router::get("admin\{controller}\{method}","{?}@{?}");
// or
// Custom
Router::get("admin\{method}\{controller}","{controller}@{method}");
Router::get('url/{id}', function ($myID) {
})->where('id', '[0-9]+');
Router::get('user/{id}/{name}', function ($myID, $name) {
})->where(['id' => '[0-9]+', 'name' => '[a-zA-Z]+']);
Router::get('user/profile', function () {
//
})->name('profile');
$url = Router::route("profile");
// Usage with parameters
Router::get('url/{id}/profile', function ($id) {
})->name('profile');
$url = Router::route('profile', ['id' => 1]);
Router::prefix('admin')->group(function () {
Router::get('users', function () {
// new url -> /admin/users
});
});
Router::middleware("middleware")->group(function () {
Router::get('/', function () {
});
Router::get('url/profile', function () {
});
});
Router::middleware(["middleware","middleware2"])->group(function () {
Router::get('/', function () {
});
Router::get('url/profile', function () {
});
});
The MIT License (MIT). Please see License File for more information.