Updated documentation

This commit is contained in:
Simon Sessingø
2016-11-17 16:33:27 +01:00
parent c94523740b
commit 99f869b57d
2 changed files with 6 additions and 10 deletions
+5 -9
View File
@@ -381,15 +381,11 @@ $route->setMethod('hello');
It's only possible to change the route BEFORE the route has initially been loaded. If you want to redirect to another route, we highly recommend that you
modify the `RouterEntry` object from a `Middleware` or `ExceptionHandler`, like the examples below.
#### Faking new route
#### Rewriting to new route
The example below will cause the router to re-route the request with another url. We are using the `url()` helper function to get the uri to another route added in the `routes.php` file.
This does require the `$request` object to be returned, otherwise the `request` object will be ignored by the router.
Using the example below will NOT inherit the rules from the other route. This means that IF you are faking a route that is enabled in `post`.
**NOTE: Use this method if you want to fully load a route (middlewares, request-method etc. will be kept).**
**NOTE: Use this method if you want to fully load another route using it's settings (request method etc).**
```php
@@ -401,8 +397,8 @@ use Pecee\SimpleRouter\RouterEntry;
class CustomMiddleware implements Middleware {
public function handle(Request $request, RouterEntry &$route = null) {
return $request->setUri(url('home'));
public function handle(Request $request, RouterEntry &$route) {
$request->setUri(url('home'));
}
}
@@ -427,7 +423,7 @@ use Pecee\SimpleRouter\RouterEntry;
class CustomMiddleware implements Middleware {
public function handle(Request $request, RouterEntry &$route = null) {
public function handle(Request $request, RouterEntry &$route) {
$route->callback('DefaultController@home');
}
+1 -1
View File
@@ -222,7 +222,7 @@ class RouterBase {
if ($route->matchRoute($this->request)) {
if (!in_array($this->request->getMethod(), $route->getRequestMethods())) {
if (count($route->getRequestMethods()) && !in_array($this->request->getMethod(), $route->getRequestMethods())) {
$routeNotAllowed = true;
continue;
}