mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 23:22:11 +00:00
Updated documentation
This commit is contained in:
@@ -18,7 +18,7 @@ The goal of this project is to create a router that is 100% compatible with the
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Basic routing (get, post, put, delete) with support for custom multiple verbs.
|
- Basic routing (`GET`, `POST`, `PUT`, `DELETE`) with support for custom multiple verbs.
|
||||||
- Regular Expression Constraints for parameters.
|
- Regular Expression Constraints for parameters.
|
||||||
- Named routes.
|
- Named routes.
|
||||||
- Generating url to routes.
|
- Generating url to routes.
|
||||||
@@ -204,42 +204,6 @@ class Router extends SimpleRouter {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Helper functions
|
|
||||||
**This is a basic example of a helper functions.**
|
|
||||||
|
|
||||||
```php
|
|
||||||
use Pecee\SimpleRouter\SimpleRouter;
|
|
||||||
|
|
||||||
function url($controller, $parameters = null, $getParams = null) {
|
|
||||||
SimpleRouter::getRoute($controller, $parameters, $getParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current csrf-token
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
function csrf_token() {
|
|
||||||
$token = new \Pecee\CsrfToken();
|
|
||||||
return $token->getToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get request object
|
|
||||||
* @return \Pecee\Http\Request
|
|
||||||
*/
|
|
||||||
function request() {
|
|
||||||
return SimpleRouter::request();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get response object
|
|
||||||
* @return \Pecee\Http\Response
|
|
||||||
*/
|
|
||||||
function response() {
|
|
||||||
return SimpleRouter::response();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Getting urls
|
## Getting urls
|
||||||
|
|
||||||
**In ```routes.php``` we have added this route:**
|
**In ```routes.php``` we have added this route:**
|
||||||
@@ -327,16 +291,6 @@ By doing this the route will now load the url ```/article/view/1``` instead of `
|
|||||||
|
|
||||||
The last thing we need to do, is to add our custom boot-manager to the ```routes.php``` file. You can create as many bootmanagers as you like and easily add them in your ```routes.php``` file.
|
The last thing we need to do, is to add our custom boot-manager to the ```routes.php``` file. You can create as many bootmanagers as you like and easily add them in your ```routes.php``` file.
|
||||||
|
|
||||||
**routes.php example:**
|
|
||||||
|
|
||||||
```php
|
|
||||||
// Add new bootmanager
|
|
||||||
SimpleRouter::addBootManager(new CustomRouterRules());
|
|
||||||
|
|
||||||
// This rule is what our custom bootmanager will use.
|
|
||||||
SimpleRouter::get('/article/view/{id}', 'ControllerArticle@view');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Easily overwrite route about to be loaded
|
## Easily overwrite route about to be loaded
|
||||||
Sometimes it can be useful to manipulate the route that's about to be loaded, for instance if a user is not authenticated or if an error occurred within your Middleware that requires
|
Sometimes it can be useful to manipulate the route that's about to be loaded, for instance if a user is not authenticated or if an error occurred within your Middleware that requires
|
||||||
some other route to be initialised. Simple PHP Router allows you to easily change the route about to be executed. All information about the current route is stored in
|
some other route to be initialised. Simple PHP Router allows you to easily change the route about to be executed. All information about the current route is stored in
|
||||||
@@ -404,12 +358,43 @@ All object inherits from `InputItem` class and will always contain these methods
|
|||||||
- `getError()` - get file upload error.
|
- `getError()` - get file upload error.
|
||||||
|
|
||||||
|
|
||||||
### Easy access your input
|
### Easy access to methods
|
||||||
Create a helper function to easily get access to the input elements.
|
Create a helper function to easily get access to the input elements.
|
||||||
|
|
||||||
Example:
|
**This is a basic example of a helper functions.**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
|
|
||||||
|
function url($controller, $parameters = null, $getParams = null) {
|
||||||
|
SimpleRouter::getRoute($controller, $parameters, $getParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current csrf-token
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
function csrf_token() {
|
||||||
|
$token = new \Pecee\CsrfToken();
|
||||||
|
return $token->getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get request object
|
||||||
|
* @return \Pecee\Http\Request
|
||||||
|
*/
|
||||||
|
function request() {
|
||||||
|
return SimpleRouter::request();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get response object
|
||||||
|
* @return \Pecee\Http\Response
|
||||||
|
*/
|
||||||
|
function response() {
|
||||||
|
return SimpleRouter::response();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get input class
|
* Get input class
|
||||||
* @return \Pecee\Http\Input\Input
|
* @return \Pecee\Http\Input\Input
|
||||||
|
|||||||
Reference in New Issue
Block a user