Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad authored Jan 23, 2025
1 parent 773aaa9 commit d2f5617
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ use CakePdf\View\PdfView;

class InvoicesController extends AppController
{
public function initialize(): void
{
parent::initialize();

// https://book.cakephp.org/5/en/controllers.html#content-type-negotiation
$this->addViewClasses([PdfView::class]);
}

// In your Invoices controller you could set additional configs,
// or override the global ones:
public function view($id = null)
Expand All @@ -128,18 +136,6 @@ class InvoicesController extends AppController
);
$this->set('invoice', $invoice);
}

/**
* Add PdfView::class to this $viewClasses property so that CakePHP automatically
* switches the view class for URLs ending with `.pdf` or with appropriate `Accept` header.
*
* @see https://book.cakephp.org/5/en/controllers.html#content-type-negotiation
* @var array<string>
*/
public function viewClasses(): array
{
return $this->viewClasses[] = PdfView::class;
}
}
```

Expand Down

0 comments on commit d2f5617

Please sign in to comment.