Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eylmz/router

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
https://github.com/eylmz/router

mvc oop php router

Last synced: about 2 months ago
JSON representation

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

Awesome Lists containing this project

README

        

# Router
Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

Version : 1.0.0
* [Installation](#installation)
* [Simple Usage](#simple-usage)
* [Available Router Methods](#available-router-methods)
* [Route Parameters](#route-parameters)
* [Controller and Method Parameters](#controller-and-method-parameters)
* [Regular Expression Constraints](#regular-expression-constraints)
* [Named Routes](#named-routes)
* [Route Groups](#route-groups)
* [License](#license)
___
### Installation
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
```
___
### Simple Usage
#### .htaccess
```
Options -Indexes
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
```

#### index.php
```php
First Parameter
// Method -> Second Parameter
Router::get("admin\{controller}\{method}","{?}@{?}");

// or

// Custom
Router::get("admin\{method}\{controller}","{controller}@{method}");

```
___
### Regular Expression Constraints
```php
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]+']);
```
___
### Named Routes
```php
Router::get('user/profile', function () {
//
})->name('profile');
```

#### Generating URLs To Named Routes
```php
$url = Router::route("profile");

// Usage with parameters
Router::get('url/{id}/profile', function ($id) {

})->name('profile');

$url = Router::route('profile', ['id' => 1]);
```
___
### Route Groups
#### Prefix URL
```php
Router::prefix('admin')->group(function () {
Router::get('users', function () {
// new url -> /admin/users
});
});
```

#### Middleware
```php
Router::middleware("middleware")->group(function () {
Router::get('/', function () {

});

Router::get('url/profile', function () {

});
});
```

#### Usage More Than One Middlewares
```php
Router::middleware(["middleware","middleware2"])->group(function () {
Router::get('/', function () {

});

Router::get('url/profile', function () {

});
});
```
___
### License
The MIT License (MIT). Please see [License File](LICENSE) for more information.