CakePdf & Cakephp 3.1.6

CakePdf & Cakephp 3.1.6

我无法让 CakePdf 工作,如果出现错误,我可以使用它。但是什么都没有出现。

CakePhp: 3.1.6

CakePdf:当前版本

我用这段代码添加了一个 InvoicesController

<?php
namespace App\Controller;
class InvoicesController extends AppController
{
    // In your Invoices controller you could set additional configs, or override the global ones:
    public function view($id)
    {
        $this->pdfConfig = array(
            'orientation' => 'landscape',
            'download' => true,
            'filename' => 'invoucne.pdf'
        );
    }
}
?>

也将此添加到我的 bootstrap.php

use Cake\Event\EventManager;
EventManager::instance()
    ->on(
        'Controller.initialize',
        function (Cake\Event\Event $event) {
            $controller = $event->subject();
            if ($controller->components()->has('RequestHandler')) {
                $controller->RequestHandler->config('viewClassMap.pdf', 'CakePdf.Pdf');
            }
        }
    );

Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);
Configure::write('CakePdf', [
    'engine' => 'CakePdf.dompdf',
    'margin' => [
        'bottom' => 15,
        'left' => 50,
        'right' => 30,
        'top' => 45
    ],
    'orientation' => 'landscape',
    'download' => true
]);

这是我的 routes.php

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

我也去 default.ctp src/Template/Layout/pdf

<h2>Rendered with default layout</h2>
<?php echo $this->fetch('content'); ?>

以及我对 Template/Invoices/pdf

的看法
<html>
<body>
<h1>test</h1>
</body>
</html>

我的 url 看起来像:

http://localhost/caketest/invoices/view/1.pdf

我用 composer 安装了它,我的插件位于 vendor/dompdf 和 vendor/friendsofcake/cakepdf

之前我遇到过这个问题,解决方法是把

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

之前

Router::scope('/', function ($routes) { //some code}

不在之后