我无法让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']);
我也在src / Template / Layout / pdf
中输入default.ctp<h2>Rendered with default layout</h2>
<?php echo $this->fetch('content'); ?>
我的模板/发票/ pdf中的观点
<html>
<body>
<h1>test</h1>
</body>
</html>
我的网址如下:
http://localhost/caketest/invoices/view/1.pdf
我用composer安装它,我的插件位于vendor / dompdf和vendor / friendsofcake / cakepdf
答案 0 :(得分:0)
在解决方案之前我遇到了这个问题
Router::extensions(['pdf']);
之前
Router::scope('/', function ($routes) { //some code}
不是在它之后