Skip to content

Commit

Permalink
Stop registering the PDF extension in the plugin routes configuration.
Browse files Browse the repository at this point in the history
By default, using plugin routes to register extensions for application
routes happens too late, which will cause the automatic PDF view
functionality to not be triggered for URLs with the `pdf` extension.
Therefore the extension is best to be registered manually when needed.

Resolves FriendsOfCake#147
  • Loading branch information
ndm2 committed Feb 8, 2016
1 parent 9d5c99b commit ffbeddf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,28 @@ composer require mpdf/mpdf

In `config/bootstrap.php` add:
```php
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);
Plugin::load('CakePdf', ['bootstrap' => true]);
```

If you plan to use [the PDF view functionality](#1-render-as-pdf-including-forced-download-in-the-browser-with-pdfview)
that automatically renders and returns the PDF for sending it to the browser, you should also register the `pdf`
extension in your `config/routes.php` file, either globally before the routes that should be affected:

```php
Router::extensions(['pdf']);
```

or for a specific route scope:

```php
Router::scope('/', function (\Cake\Routing\RouteBuilder $routes) {
$routes->extensions(['pdf']);
// ...
});
```

Further setup information can be found in the usage section.


## Configuration

Expand Down Expand Up @@ -144,11 +163,15 @@ You can create PDF view and layout files for your controller actions and have th
Place the view templates in a 'pdf' subdir, for instance `src/Template/Invoices/pdf/view.ctp`
Layouts will be in `src/Template/Layouts/pdf/default.ctp`

Make sure your InvoicesController has RequestHandler Component in the `$components` array.
Browse to http://localhost/invoices/view/1.pdf
Make sure your `InvoicesController` class
[loads the `RequestHandler` component](http://book.cakephp.org/3.0/en/controllers/components/request-handling.html)
and browse to `http://localhost/invoices/view/1.pdf`

Additionally you can map resources by adding `Router::mapResources(['Invoices']);` to your routes
file and you can access the same document at http://localhost/invoices/1.pdf
file and you can access the same document at `http://localhost/invoices/1.pdf`

In case you don't want to use the `pdf` extension in your URLs, you can omit registering it in your routes
configuration, and have your requests send a `Accept: application/pdf` header instead.


### 2: Create PDF for email attachment, file storage etc.
Expand Down
4 changes: 0 additions & 4 deletions config/routes.php

This file was deleted.

0 comments on commit ffbeddf

Please sign in to comment.