我已经在app/plugins文件夹中安装了CakePdf插件,并按照所有可能的文档进行了操作,因此我的设置如下:
// 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布局,以及模型操作的templates文件夹内的PDF文件夹,但是,如果我访问
app/users/agendapdf.pdf
,我会得到以下信息:
我真的很想知道出了什么问题,以及如何修复它使其正常工作。在UsersController中未定义agendapdf.pdf操作 错误:在文件src/Controller/UsersController.php中创建UsersController :: agendapdf.pdf()。
config/routes.php
文件中,Router::extensions(['pdf']);
调用确切地在哪里被调用了?请展示一些相关的上下文。 - ndmRouter::extensions('pdf']);
应该放在正确位置。你应该将其添加到与agendaPdf()
方法相关的Router::scope();
之前。所以很可能你正在使用默认的路由Router::scope('/', function ($routes) {
,因此在这之前添加它。 - AKKAwebextensions
调用是在config/routes.php
的最后进行的。 - WpDoe