Skip to content

Commit d2f5617

Browse files
authored
Update README.md
1 parent 773aaa9 commit d2f5617

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ use CakePdf\View\PdfView;
114114

115115
class InvoicesController extends AppController
116116
{
117+
public function initialize(): void
118+
{
119+
parent::initialize();
120+
121+
// https://book.cakephp.org/5/en/controllers.html#content-type-negotiation
122+
$this->addViewClasses([PdfView::class]);
123+
}
124+
117125
// In your Invoices controller you could set additional configs,
118126
// or override the global ones:
119127
public function view($id = null)
@@ -128,18 +136,6 @@ class InvoicesController extends AppController
128136
);
129137
$this->set('invoice', $invoice);
130138
}
131-
132-
/**
133-
* Add PdfView::class to this $viewClasses property so that CakePHP automatically
134-
* switches the view class for URLs ending with `.pdf` or with appropriate `Accept` header.
135-
*
136-
* @see https://book.cakephp.org/5/en/controllers.html#content-type-negotiation
137-
* @var array<string>
138-
*/
139-
public function viewClasses(): array
140-
{
141-
return $this->viewClasses[] = PdfView::class;
142-
}
143139
}
144140
```
145141

0 commit comments

Comments
 (0)