Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/eylmz/router
- Owner: eylmz
- License: mit
- Created: 2017-08-18T05:40:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-19T07:35:44.000Z (over 7 years ago)
- Last Synced: 2024-11-28T23:48:55.314Z (2 months ago)
- Topics: mvc, oop, php, router
- Language: PHP
- Homepage: http://emre.pw
- Size: 20.5 KB
- Stars: 14
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 OnRewriteCond %{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.