如何在CakePHP 3手动安装插件? [英] How to install a plugin manually in CakePHP 3?

查看:482
本文介绍了如何在CakePHP 3手动安装插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 Composer ,因此必须安装 CakePDF插件,但是以下官方CakePHP文档中的示例似乎不起作用。

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。)将插件复制到 app / plugins / CakePdf

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

2。)更新应用程序的 composer.json 文件,如下所示:

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。)在 bootstrap中加载插件。 php

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

4。)添加路由器扩展:

4.) Added router extensions:

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

5。)从插件的文档尝试了一个非常简单的示例:

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.

推荐答案

您收到此错误是因为 vendor / composer / / code>,您可以看到一些 autoload _ *。php 文件。这些文件包含加载类的路径。我想没有人可以安全地告诉你要更新什么以及在这些文件中的位置。

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 - 在本地计算机上复制 composer.json 并运行 composer update 。然后移动在您的应用程序内创建的文件。我建议先备份。很可能你必须移动的东西是:

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 - 开始更新 vendor / composer / autoload_ * .php 与插件的路径。很可能你只需要更新以下两个文件:

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 code> vendor / composer / autoload_psr4.php 。我个人不会选择第二个解决方案,我只是添加它作为一种选择,以防万一。

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.

这篇关于如何在CakePHP 3手动安装插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆