Home>

Purpose: In cakephp, I want to convert the HTML screen to PDF using CakePdf and wkhtmltopdf.
However, after setting bootstrap.php and routes.php, it became "Error: An Internal Error Has Occurred.".
Looking at the error log, it says "** Error: [Cake \ Core \ Exception \ MissingPluginException]Plugin CakePdf could not be found. **"
Each source is listed below.
The plugin itself is located at/vendor/friendsofcake/cakepdf.
Uploading only routes.php will not cause an error.
When bootstrap.php is uploaded as follows, the above error appears.
I plugged in the plug-in again, but it cannot be solved.
Please use your strength.
Thank you.

bootstrap.php

<? php
if (version_compare (PHP_VERSION, '5.5.9')<0) {
    trigger_error ('Your PHP version must be equal or higher than 5.5.9 to use CakePHP.', E_USER_ERROR);
}
if (! extension_loaded ('intl')) {
    trigger_error ('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
}
if (! extension_loaded ('mbstring')) {
    trigger_error ('You must enable the mbstring extension to use CakePHP.', E_USER_ERROR);
}
require __DIR__. '/paths.php';
require ROOT. DS. 'vendor'. DS. 'autoload.php';
require CORE_PATH. 'config'. DS. 'bootstrap.php';
use Cake \ Cache \ Cache;
use Cake \ Console \ ConsoleErrorHandler;
use Cake \ Core \ App;
use Cake \ Core \ Configure;
use Cake \ Core \ Configure \ Engine \ PhpConfig;
use Cake \ Core \ Plugin;
use Cake \ Database \ Type;
use Cake \ Datasource \ ConnectionManager;
use Cake \ Error \ ErrorHandler;
use Cake \ Log \ Log;
use Cake \ Mailer \ Email;
use Cake \ Network \ Request;
use Cake \ Utility \ Inflector;
use Cake \ Utility \ Security;
use Cake \ Routing \ DispatcherFactory;
try {
    Configure :: config ('default', new PhpConfig ());
    Configure :: load ('app', 'default', false);
} catch (\ Exception $e) {
    exit ($e->getMessage (). "\ n");
}
if (Configure :: read ('debug')) {
    Configure :: write ('Cache._cake_model_.duration', '+2 minutes');
    Configure :: write ('Cache._cake_core_.duration', '+2 minutes');
}
date_default_timezone_set ('Asia/Tokyo');
/ *
 * Configure the mbstring extension to use the correct encoding.
 * /
mb_internal_encoding (Configure :: read ('App.encoding'));
ini_set ('intl.default_locale', Configure :: read ('App.defaultLocale'));
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
    (new ConsoleErrorHandler (Configure :: read ('Error')))->register ();
} else {
    (new ErrorHandler (Configure :: read ('Error')))->register ();
}
if ($isCli) {
    require __DIR__. '/bootstrap_cli.php';
}
if (! Configure :: read ('App.fullBaseUrl')) {
    $s = null;
    if (env ('HTTPS')) {
        $s = 's';
    }
    $httpHost = env ('HTTP_HOST');if (isset ($httpHost)) {
        Configure :: write ('App.fullBaseUrl', 'http'. $S. ': //'. $HttpHost);
    }
    unset ($httpHost, $s);
}
Cache :: config (Configure :: consume ('Cache'));
ConnectionManager :: config (Configure :: consume ('Datasources'));
Email :: configTransport (Configure :: consume ('EmailTransport'));
Email :: config (Configure :: consume ('Email'));
Log :: config (Configure :: consume ('Log'));
Security :: salt (Configure :: consume ('Security.salt'));
Request :: addDetector ('mobile', function ($request) {
    $detector = new \ Detection \ MobileDetect ();
    return $detector->isMobile ();
});
Request :: addDetector ('tablet', function ($request) {
    $detector = new \ Detection \ MobileDetect ();
    return $detector->isTablet ();
});
Plugin :: load ('Migrations');
if (Configure :: read ('debug')) {
        Plugin :: load ('DebugKit', ['bootstrap' =>true]);
}
DispatcherFactory :: add ('Asset');
DispatcherFactory :: add ('Routing');
DispatcherFactory :: add ('ControllerFactory');
Type :: build ('time')
    ->useImmutable ();
Type :: build ('date')
    ->useImmutable ();
Type :: build ('datetime')
    ->useImmutable ();
Type :: build ('timestamp')
    ->useImmutable ();
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

<? 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 ();