mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
[TASK] Updated readme
This commit is contained in:
@@ -24,6 +24,11 @@ Add the latest version pf Simple PHP Router to your ```composer.json```
|
|||||||
- Sub-Domain Routing
|
- Sub-Domain Routing
|
||||||
- CSRF Protection
|
- CSRF Protection
|
||||||
- Optinal/required parameters
|
- Optinal/required parameters
|
||||||
|
- Aliases for ```RouterRoute```
|
||||||
|
|
||||||
|
### Known issues
|
||||||
|
|
||||||
|
- Posting invalid/unsupported request-type throws 404 instead of "method not allowed" exception, unless defined within a group.
|
||||||
|
|
||||||
## Initialising the router
|
## Initialising the router
|
||||||
|
|
||||||
@@ -44,7 +49,7 @@ SimpleRouter::init($defaultControllerNamespace);
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Adding routes
|
## Adding routes
|
||||||
Remember the ```routes.php``` file you required in your ```index.php```? This file will contain all your custom rules for routing.
|
Remember the ```routes.php``` file you required in your ```index.php```? This file will contain all your custom rules for routing.
|
||||||
This router is heavily inspired by the Laravel 5.* router, so anything you find in the Laravel documentation should work here as well.
|
This router is heavily inspired by the Laravel 5.* router, so anything you find in the Laravel documentation should work here as well.
|
||||||
|
|
||||||
### Basic example
|
### Basic example
|
||||||
@@ -54,8 +59,8 @@ use Pecee\SimpleRouter\SimpleRouter;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This route will match the url /v1/services/answers/1/
|
* This route will match the url /v1/services/answers/1/
|
||||||
|
|
||||||
* The middleware is just a class that renders before the
|
* The middleware is just a class that renders before the
|
||||||
* Controller or callback is loaded. This is useful for stopping
|
* Controller or callback is loaded. This is useful for stopping
|
||||||
* the request, for instance if a user is not authenticated.
|
* the request, for instance if a user is not authenticated.
|
||||||
*/
|
*/
|
||||||
@@ -66,13 +71,13 @@ SimpleRouter::group(['prefix' => 'v1', 'middleware' => '\MyWebsite\Middleware\So
|
|||||||
|
|
||||||
SimpleRouter::get('/answers/{id}', 'ControllerAnswers@show')
|
SimpleRouter::get('/answers/{id}', 'ControllerAnswers@show')
|
||||||
->where(['id' => '[0-9]+');
|
->where(['id' => '[0-9]+');
|
||||||
|
|
||||||
// Resetful ressource
|
// Resetful ressource
|
||||||
SimpleRouter::ressource('/rest', 'ControllerRessource');
|
SimpleRouter::ressource('/rest', 'ControllerRessource');
|
||||||
|
|
||||||
// Load the entire controller (where url matches method names - getIndex(), postIndex() etc)
|
// Load the entire controller (where url matches method names - getIndex(), postIndex() etc)
|
||||||
SimpleRouter::controller('/controller', 'ControllerDefault');
|
SimpleRouter::controller('/controller', 'ControllerDefault');
|
||||||
|
|
||||||
// Example of providing callback instead of Controller
|
// Example of providing callback instead of Controller
|
||||||
SimpleRouter::get('/something', function() {
|
SimpleRouter::get('/something', function() {
|
||||||
die('Callback example');
|
die('Callback example');
|
||||||
@@ -84,7 +89,7 @@ SimpleRouter::group(['prefix' => 'v1', 'middleware' => '\MyWebsite\Middleware\So
|
|||||||
|
|
||||||
### Doing it the object oriented (hardcore) way
|
### Doing it the object oriented (hardcore) way
|
||||||
|
|
||||||
The ```SimpleRouter``` class referenced in the previous example, is just a simple helper class that knows how to communicate with the ```RouterBase``` class.
|
The ```SimpleRouter``` class referenced in the previous example, is just a simple helper class that knows how to communicate with the ```RouterBase``` class.
|
||||||
If you are up for a challenge, want the full control or simply just want to create your own ```Router``` helper class, this example is for you.
|
If you are up for a challenge, want the full control or simply just want to create your own ```Router``` helper class, this example is for you.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -171,7 +176,7 @@ In ```routes.php``` we have added this route:
|
|||||||
|
|
||||||
In the template we then call:
|
In the template we then call:
|
||||||
|
|
||||||
```url('myController@show', ['id' => 22], ['category' => 'shoes']);```
|
```url('myController@show', ['id' => 22], ['category' => 'shoes']);```
|
||||||
|
|
||||||
Result url is:
|
Result url is:
|
||||||
|
|
||||||
@@ -183,4 +188,4 @@ While I work on a better documentation, please refer to the Laravel 5 routing do
|
|||||||
http://laravel.com/docs/5.1/routing
|
http://laravel.com/docs/5.1/routing
|
||||||
|
|
||||||
## Easily extendable
|
## Easily extendable
|
||||||
The router can be easily extended to customize your needs.
|
The router can be easily extended to customize your needs.
|
||||||
|
|||||||
Reference in New Issue
Block a user