File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed
Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,14 @@ use CakePdf\View\PdfView;
114114
115115class 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
You can’t perform that action at this time.
0 commit comments