mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 14:02:14 +00:00
Bugfixes
This commit is contained in:
@@ -356,7 +356,7 @@ The last thing we need to do, is to add our custom boot-manager to the ```routes
|
||||
## Easily overwrite route about to be loaded
|
||||
Sometimes it can be useful to manipulate the route about to be loaded.
|
||||
simple-php-router allows you to easily change the route about to be executed.
|
||||
All information about the current route is stored in the ```\Pecee\SimpleRouter\RouterBase``` instance.
|
||||
All information about the current route is stored in the ```\Pecee\SimpleRouter\RouterBase``` instance's `loadedRoute` property.
|
||||
|
||||
For easy access you can use the shortcut method `\Pecee\SimpleRouter\SimpleRouter::router()`.
|
||||
|
||||
@@ -376,12 +376,19 @@ $route->setMethod('hello');
|
||||
|
||||
### Examples
|
||||
|
||||
#### Faking new route
|
||||
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 `RouterRoute` object from a `Middleware` or `ExceptionHandler`, for like the examples below.
|
||||
modify the `RouterEntry` object from a `Middleware` or `ExceptionHandler`, like the examples below.
|
||||
|
||||
#### Faking 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).**
|
||||
|
||||
The example below will cause the router to re-route the request with the "fake" uri. This does require the `$request` object to be returned,
|
||||
otherwise the `request` object will be ignored by the router.
|
||||
|
||||
```php
|
||||
namespace demo\Middlewares;
|
||||
@@ -393,7 +400,7 @@ use Pecee\SimpleRouter\RouterEntry;
|
||||
class CustomMiddleware implements Middleware {
|
||||
|
||||
public function handle(Request $request, RouterEntry &$route = null) {
|
||||
return $request->setUri('/home');
|
||||
return $request->setUri(url('home'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -407,6 +414,8 @@ on some criteria's for the request.
|
||||
The callback below will fire immediately after the `Middleware` or `ExceptionHandler` has been loaded, as they are loaded before the route is rendered.
|
||||
If you wish to change the callback from outside, please have this in mind.
|
||||
|
||||
**NOTE: Use this method if you want to load another controller. No additional middlewares or rules will be loaded.**
|
||||
|
||||
```php
|
||||
namespace demo\Middlewares;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user