cakepdf - 子文件夹/ p​​df /缺少模板

时间:2018-01-15 17:10:20

标签: cakephp

我按照guide中描述的每个安装和配置步骤进行操作,我正在尝试渲染pdf并强制下载。 正如指南所说,模板应放在“pdf”子文件夹中,如“invoice / pdf / view.ctp”,以触发pdf渲染(如果我已经理解),我无法想象Cake如何找到一个在子文件夹中查看模板。 Cake实际上显示了一个丢失的模板异常。 我被困在这里了!

这是我在bootstrap.php中的配置

Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]);

Configure::write('CakePdf', [
        'engine' => 'CakePdf.WkHtmlToPdf',
        'margin' => [
            'bottom' => 30,
            'left' => 20,
            'right' => 20,
            'top' => 30
        ],
        'orientation' => 'portrait',
        'download' => true,
    //    'encoding' => 'UTF-8'
    ]);

在routes.php中,我在Router::extensions(['pdf']);

之前添加了Router::scope('/', function (RouteBuilder $routes) {...

这是我的控制器动作:

public function savepdf($id_paz){   
        $anamnesi = $this->AnamnesiPazienti->find()->where(['pazienti_id' => $id_paz]);
        $this->loadModel('Pazienti');
        $paziente = $this->Pazienti->get($id_paz);  
        $this->viewBuilder()->options([
                'pdfConfig' => [
                        'filename' => 'Anam_paz-' . $id_paz . '.pdf'
                ]
        ]); 
        $this->set('paziente', $paziente);
        $this->set('anamnesi', $anamnesi);
        $this->set('modelPazienti', $this->Pazienti);

    }

---编辑:

这是堆栈跟踪:

2018-01-17 10:07:07 Error: [Cake\Controller\Exception\MissingActionException] Action AnamnesiPazientiController::savepdf() could not be found, or is not accessible.
    Exception Attributes: array (
      'controller' => 'AnamnesiPazientiController',
      'action' => 'savepdf',
      'prefix' => '',
      'plugin' => false,
    )
    Request URL: /anamnesi-pazienti/savepdf/8.pdf
    Stack Trace:
    #0 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(119): Cake\Controller\Controller->invokeAction()
    #1 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(93): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\AnamnesiPazientiController))
    #2 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/BaseApplication.php(108): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #3 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
    #4 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(104): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #5 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
    #6 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(97): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #7 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
    #8 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(98): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #9 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
    #10 /media/dati/Lavori/smilodon/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php(52): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #11 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(65): DebugKit\Middleware\DebugKitMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
    #12 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #13 /media/dati/Lavori/smilodon/vendor/cakephp/cakephp/src/Http/Server.php(81): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
    #14 /media/dati/Lavori/smilodon/webroot/index.php(40): Cake\Http\Server->run()
    #15 {main}

0 个答案:

没有答案