Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 7e1d0f9

Browse files
committed
Merge branch 'hotfix/195'
Close #195
2 parents a370fb6 + ca6d780 commit 7e1d0f9

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

doc/book/plugins.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,44 @@ As an example:
4040

4141
```php
4242
use Zend\Mvc\Controller\AbstractActionController;
43-
use Zend\View\Model\JsonModel;
4443

4544
class SomeController extends AbstractActionController
4645
{
47-
protected $acceptCriteria = [
48-
'Zend\View\Model\JsonModel' => [
49-
'application/json',
50-
],
51-
'Zend\View\Model\FeedModel' => [
52-
'application/rss+xml',
53-
],
54-
];
55-
56-
public function apiAction()
57-
{
58-
$viewModel = $this->acceptableViewModelSelector($this->acceptCriteria);
59-
60-
// Potentially vary execution based on model returned
61-
if ($viewModel instanceof JsonModel) {
62-
// ...
63-
}
64-
}
46+
protected $acceptCriteria = [
47+
\Zend\View\Model\ViewModel::class => [
48+
'text/html',
49+
'application/xhtml+xml',
50+
],
51+
\Zend\View\Model\JsonModel::class => [
52+
'application/json',
53+
'application/javascript',
54+
],
55+
\Zend\View\Model\FeedModel::class => [
56+
'application/rss+xml',
57+
'application/atom+xml',
58+
],
59+
];
60+
61+
public function apiAction()
62+
{
63+
$viewModel = $this->acceptableViewModelSelector($this->acceptCriteria);
64+
65+
// Potentially vary execution based on model returned
66+
if ($viewModel instanceof \Zend\View\Model\JsonModel) {
67+
// ...
68+
}
69+
}
6570
}
6671
```
6772

68-
The above would return a standard `Zend\View\Model\ViewModel` instance if the
69-
criteria is not met, and the specified view model types if the specific criteria
70-
is met. Rules are matched in order, with the first match "winning."
73+
The above would return a standard `Zend\View\Model\ViewModel` instance if no
74+
criterias are met, and the specified view model types if a specific criteria
75+
is met. Rules are matched in order, with the first match "winning".
76+
Make sure to put your fallback view model *first* as a fallback for unknown
77+
content types or `*/*`.
78+
79+
> Browsers are sending `*/*` as last content type of the Accept header so you have to define every
80+
> acceptable view model and their content type.
7181
7282
## Forward Plugin
7383

0 commit comments

Comments
 (0)