mirror of
https://github.com/WilliamAAK/Route2.git
synced 2025-04-19 21:07:20 +00:00
Docs: Update
This commit is contained in:
parent
d34738f094
commit
3c72d72789
29
README.md
29
README.md
@ -1,16 +1,17 @@
|
|||||||
# Route2
|
# Route2 🛣️
|
||||||
|
|
||||||
A simple routing system for PHP web applications.
|
A simple routing system for PHP web applications.
|
||||||
|
|
||||||
### Features:
|
### Features:
|
||||||
- Define routes for specific HTTP methods (GET, POST, PUT, DELETE, etc.).
|
- **Simplicity**: Easily map URLs to specific callback functions.
|
||||||
- Apply middleware to routes or groups of routes.
|
- **Parameters**: Flexible URL handling with parameters (e.g., `/user/$id`).
|
||||||
- Group routes under a common prefix for better organization.
|
- **Middleware**: Register functions to execute **before** and **after** routes.
|
||||||
- Support for route parameters (e.g., `/user/$id`) and optional parameters (e.g., `/user/$id?`).
|
- **Grouping**: Organize related routes and apply group-specific middleware.
|
||||||
|
- **Lightweight**: A single-file, no-frills routing solution with zero dependencies.
|
||||||
|
|
||||||
### Example:
|
### Example:
|
||||||
```php
|
```php
|
||||||
// Setup the routing context. This method must be called before defining any routes
|
// Initialize the router. This method must be called before defining any routes
|
||||||
Route2::setup();
|
Route2::setup();
|
||||||
|
|
||||||
// Define a GET route
|
// Define a GET route
|
||||||
@ -58,7 +59,7 @@ Route2::group('/admin', function () {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
# Installation
|
## Installing
|
||||||
|
|
||||||
### Composer:
|
### Composer:
|
||||||
|
|
||||||
@ -88,14 +89,12 @@ Its all in a single file; include it in your project like so.
|
|||||||
require '/YourPath/Route2.php'
|
require '/YourPath/Route2.php'
|
||||||
```
|
```
|
||||||
|
|
||||||
# Usage
|
## Using Route2
|
||||||
|
|
||||||
To get started quickly you may copy this into your project.
|
To get started quickly you may copy this into your project.
|
||||||
|
|
||||||
### Classic mode
|
### Classic mode
|
||||||
|
|
||||||
Defualt PHP behavior
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@ -161,17 +160,19 @@ for ($nbRequests = 0; !$maxRequests || $nbRequests < $maxRequests; ++$nbRequests
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# Accessing your routes
|
## Accessing your routes
|
||||||
|
|
||||||
The simplest way to access your routes is to put the file in your folder and run it. E.g if you request `http://your.site/yourscript.php/your/route` the route will be automatically converted to `/your/route`
|
The simplest way to access your routes is to put the file in your folder and run it.
|
||||||
|
|
||||||
# Rewriting requests
|
For example if you request ```http://your.site/yourscript.php/your/route``` the route will be automatically adjust to `/your/route`.
|
||||||
|
|
||||||
|
## Rewriting requests
|
||||||
|
|
||||||
Want to hide that pesky script name (e.g `index.php`) from the URL?
|
Want to hide that pesky script name (e.g `index.php`) from the URL?
|
||||||
|
|
||||||
### FrankenPHP:
|
### FrankenPHP:
|
||||||
|
|
||||||
It is recommended that you use FrankenPHP the modern PHP app server. This behavior is enabled by default.
|
It is recommended that you use [FrankenPHP](https://frankenphp.dev); modern PHP app server. This behavior is enabled by default.
|
||||||
|
|
||||||
### NGINX:
|
### NGINX:
|
||||||
|
|
||||||
|
@ -8,14 +8,15 @@ use InvalidArgumentException;
|
|||||||
* A simple routing system for PHP web applications.
|
* A simple routing system for PHP web applications.
|
||||||
*
|
*
|
||||||
* ### Features:
|
* ### Features:
|
||||||
* - Define routes for specific HTTP methods (GET, POST, PUT, DELETE, etc.).
|
* - **Simplicity**: Easily map URLs to specific callback functions.
|
||||||
* - Apply middleware to routes or groups of routes.
|
* - **Parameters**: Flexible URL handling with parameters (e.g., `/user/$id`).
|
||||||
* - Group routes under a common prefix for better organization.
|
* - **Middleware**: Register functions to execute **before** and **after** routes.
|
||||||
* - Support for route parameters (e.g., `/user/$id`) and optional parameters (e.g., `/user/$id?`).
|
* - **Grouping**: Organize related routes and apply group-specific middleware.
|
||||||
|
* - **Lightweight**: A single-file, no-frills routing solution with zero dependencies.
|
||||||
*
|
*
|
||||||
* ### Example:
|
* ### Example:
|
||||||
* ```php
|
* ```php
|
||||||
* // Setup the routing context. This method must be called before defining any routes
|
* // Initialize the router. This method must be called before defining any routes
|
||||||
* Route2::setup();
|
* Route2::setup();
|
||||||
*
|
*
|
||||||
* // Define a GET route
|
* // Define a GET route
|
||||||
|
Loading…
x
Reference in New Issue
Block a user