How to install a plugin manually in CakePHP 3?

纵饮孤独 提交于 2019-12-12 02:59:15

问题


I am unable to use Composer and thus have to install CakePDF plugin manually, but following examples from official CakePHP documentation does not seem to work.

So here is installation flow that I have followed:

1.) Copied the plugin to app/plugins/CakePdf

2.) Updated the app's composer.json file, like following:

"autoload": {
    "psr-4": {
            "CakePdf\\": "./plugins/CakePdf/src",
            "CakePdf\\Test\\": "./plugins/CakePdf/tests"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Test\\": "tests",
        "Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
        "CakePdf\\": "./plugins/CakePdf/src",
        "CakePdf\\Test\\": "./plugins/CakePdf/tests"
    }
}

3.) Loaded the plugin in bootstrap.php:

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

4.) Added router extensions:

Router::extensions(['pdf']);

5.) Tried a very simple sample from plugin's doc:

$cakePdf = new CakePdf(array(
    'engine' => 'CakePdf.DomPdf',
    'pageSize' => 'A4',
    'orientation' => 'portrait'
)); 

$html = '<html><head><body><p>Pdftest</p></body></head></html>';

$rawPdf = $CakePdf->output($html);

However the code breaks at the first line and the following error message is provided:

Class 'App\Controller\CakePdf' not found

I would really appreciate any help or guidance for how a plugin should be installed manually.

If there is any other information that I need to provide, just ask.


回答1:


You are getting this error because inside vendor/composer/ you can see some autoload_*.php files. These files hold the paths to load your classes. I think no one can safely tell you what to update and where in these files.

So you have two solutions:

1 - Copy composer.json on a local machine and run composer update. Then move the files created inside your app. I would suggest to take a backup before. Most probably the things that you will have to move are:

 vendor/
 composer.json
 composer.lock

2 - Start updating the files inside vendor/composer/autoload_*.php with the paths from the plugin. Most probably you will only need to update the following two files:

vendor/cakephp-plugins.php and vendor/composer/autoload_psr4.php. Personally I wouldn't choose the second solution I am just adding it as an alternative just in case.



来源:https://stackoverflow.com/questions/36163204/how-to-install-a-plugin-manually-in-cakephp-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!