cakephp3.3をにて、WkHtmlToPdfを使ってPDF生成を行いたいです。
しかし、「View class "CakePdf.Pdf" is missing」とエラーが出てしましい上手くいきません。
---前提---
・WkHtmlToPdfのインストールは完了。
・別プロジェクトからごっそりvendor以下にfriendsofcake/cakepdf...を移動。
・config/bootstrap内に下記追加
・config/routes内に下記追加
・admin/OrderController.php内に下記追加
・admin/Order/pdf/invoice.ctp ←これをPDF化したいです。
・admin/Order/calendar.ctp ←この中のボタンを押して、PDF生成!
・Template/Layout/default.ctpを追加しました。
別プロジェクト(前任者はもういません)ではできるのですが、本プロジェクトから私がやっておりまして調べたかぎりのことは設定してみたんですができません。
friendsofcake/cakepdfをコピーしてきたのがいけないでしょうか。
ご教授よろしくお願いいたします。
☆追記☆
下記の通り実行しました。
下にcomposer.jsonを追加記載しました。
既存のcomposer.json内に、「"friendsofcake/CakePdf": "^3.2"」を追加しました!
その後SSHで接続し、まず削除しました。
$composer remove friendsofcake/cakepdf
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 7 removals
- Removing zendframework/zend-diactoros (1.8.5)
- Removing psr/log (1.0.2)
- Removing psr/http-message (1.0.1)
- Removing friendsofcake/cakepdf (3.5.1)
- Removing cakephp/chronos (1.2.2)
- Removing cakephp/cakephp (3.6.10)
- Removing aura/intl (3.0.0)
Generating autoload files
次にインストールしました。
$composer require friendsofcake/cakepdf を実行!
Using version ^3.5 for friendsofcake/cakepdf
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing zendframework/zend-diactoros (1.8.5): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing aura/intl (3.0.0): Downloading (100%)
- Installing cakephp/chronos (1.2.2): Downloading (100%)
- Installing cakephp/cakephp (3.6.10): Downloading (100%)
- Installing friendsofcake/cakepdf (3.5.1): Downloading (100%)
cakephp/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
friendsofcake/cakepdf suggests installing dompdf/dompdf (If you wish to use the DomPdf engine)
friendsofcake/cakepdf suggests installing tecnickcom/tcpdf (If you wish to use the Tcpdf engine)
friendsofcake/cakepdf suggests installing mpdf/mpdf (If you wish to use the Mpdf engine)
Writing lock file
Generating autoload files
このように表示されました。
vendor以下を確認しても追加されてません。
bootstrap.php
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]); Configure::write('CakePdf', [ 'engine' => ['className' =>'CakePdf.WkHtmlToPdf', 'binary' => '/usr/local/bin/wkhtmltopdf', ], 'options' => [ 'print-media-type' => false, 'outline' => true, 'dpi' => 96 ], 'margin' => [ 'bottom' => 5, 'left' => 10, 'right' => 10, 'top' => 5 ], // 'orientation' => 'landscape', 'orientation' => 'portrait', 'download' => false ]);
routes.php
Router::defaultRouteClass(DashedRoute::class); Router::extensions(['pdf','json','xml','ajax']); Router::prefix('admin',function($routes) { $routes->extensions(['json','xml','ajax']); $routes->fallbacks('DashedRoute'); }); Router::scope('/', function (RouteBuilder $routes) { $routes->extensions(['json', 'xml', 'ajax']); $routes->connect('/', ['controller' => 'Login', 'action' => 'login']); $routes->connect('/admin', ['controller' => 'Login', 'action' => 'index', 'prefix' => 'admin']); $routes->fallbacks(DashedRoute::class); }); Plugin::routes();
hogeController.php
public function invoice(){ $this->viewClass = 'CakePdf.Pdf'; ~以下~ いろいろ処理 }
calendar.ctp
var form = document.createElement("form"); form.action = '/admin/order/invoice/<?= $day ?>.pdf'; form.method = 'post'; form.target = '_blank';
composer.json
{ "name": "cakephp/app", "description": "CakePHP skeleton app", "homepage": "http://cakephp.org", "type": "project", "license": "MIT", "require": { "friendsofcake/CakePdf": "^3.5" }, "require-dev": { "psy/psysh": "@stable", "cakephp/debug_kit": "~3.2", "cakephp/bake": "~1.1" }, "suggest": { "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.", "phpunit/phpunit": "Allows automated tests to be run without system-wide install.", "cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP." }, "autoload": { "psr-4": { "App\": "src" } }, "autoload-dev": { "psr-4": { "App\Test\": "tests", "Cake\Test\": "./vendor/cakephp/cakephp/tests" } }, "scripts": { "post-install-cmd": "App\Console\Installer::postInstall", "post-create-project-cmd": "App\Console\Installer::postInstall", "post-autoload-dump": "Cake\Composer\Installer\PluginInstaller::postAutoloadDump", "check": [ "@test", "@cs-check" ], "cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "test": "phpunit --colors=always" } }
回答1件
あなたの回答
tips
プレビュー