我已经安装了CakePdf https://github.com/FriendsOfCake/CakePdf插件放在 app/plugins 文件夹中并遵循所有可能的文档,因此我的设置如下:
// config/bootstrap.php
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);
Configure::write('CakePdf', [
'engine' => 'CakePdf.WkHtmlToPdf',
'binary' => '/wkhtmltopdf/bin/wkhtmltopdf',
'margin' => [
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
],
'orientation' => 'landscape',
'download' => true
]);
// config/routes.php
Router::extensions(['pdf']);
// controller/AppController.php
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => ['Form' => ['fields' => ['username' => 'email', 'password' => 'password']]],
'loginAction' => ['controller' => 'Users', 'action' => 'login'],
'loginRedirect' => ['controller' => 'Users', 'action' => 'index'],
'logoutRedirect' => ['controller' => 'Users', 'action' => 'login'],
'authorize' => 'Controller'
]);
}
这是一个示例agendaPdf
动作看起来像:
function agendaPdf(){
$agenda = 'sample agenda';
$this->viewBuilder()->options([
'pdfConfig' => [
'orientation' => 'portrait',
'filename' => 'agenda_123'
]
]);
$this->set('agenda', $agenda);
}
我已经完成了 PDF 布局,并且模板文件夹内有一个用于模型操作的 PDF 文件夹,但是,如果我转到app/users/agendapdf.pdf
,我收到以下消息:
行动议程pdf.pdf未在UsersController中定义
错误:在文件:src/Controller/UsersController.php 中创建 UsersController::agendapdf.pdf()。
我真的很想知道可能出了什么问题以及如何修复它以使其正常工作。