Skip to content

Commit

Permalink
Merge pull request #142 from chaos0815/docs
Browse files Browse the repository at this point in the history
improves Redirect plugin docs showing how to set status code. #4
  • Loading branch information
Ocramius authored Dec 5, 2022
2 parents 111e08a + 44ea993 commit c54eaeb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 10 additions & 2 deletions docs/book/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ class SomeController extends AbstractActionController
```

The above would return a standard `Laminas\View\Model\ViewModel` instance if no
criterias are met, and the specified view model types if a specific criteria
criteria are met, and the specified view model types if a specific criterion
is met. Rules are matched in order, with the first match "winning".
Make sure to put your fallback view model *first* as a fallback for unknown
content types or `*/*`.

> Browsers are sending `*/*` as last content type of the Accept header so you have to define every
> Browsers are sending `*/*` as last content type of the Accept header, so you have to define every
> acceptable view model and their content type.
## Forward Plugin
Expand Down Expand Up @@ -192,6 +192,9 @@ The `Redirect` plugin does this work for you. It offers three methods:
In each case, the `Response` object is returned. If you return this immediately,
you can effectively short-circuit execution of the request.

By default, the returned `Response` object has the HTTP status set to `302`. To
set a different status use the `Laminas\Http\Respons::setStatusCode` method.

> ### Requires MvcEvent
>
> This plugin requires that the controller invoking it implements
Expand All @@ -202,6 +205,11 @@ As an example:

```php
return $this->redirect()->toRoute('login-success');

// with status code using fluent interface
return $this->redirect()
->toRoute('new-landing-page')
->setStatusCode(\Laminas\Http\Response::STATUS_CODE_301);
```

## Url Plugin
Expand Down
3 changes: 0 additions & 3 deletions src/Controller/Plugin/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Laminas\Mvc\InjectApplicationEventInterface;
use Laminas\Mvc\MvcEvent;

/**
* @todo allow specifying status code as a default, or as an option to methods
*/
class Redirect extends AbstractPlugin
{
protected $event;
Expand Down

0 comments on commit c54eaeb

Please sign in to comment.