简体   繁体   English

在Laravel 4中无需使用作曲器即可手动下载tcpdf

[英]Download tcpdf manually without using composer in Laravel 4

I'm trying to download TCPDF library to my project using Composer (Laravel 4), but I can't. 我正在尝试使用Composer(Laravel 4)将TCPDF库下载到我的项目中,但是我不能。

Sometimes this error occurs 有时会发生此错误

( http://i.stack.imgur.com/aaPDz.jpg ) http://i.stack.imgur.com/aaPDz.jpg http://mahdedu.org/1.jpg

and sometime this error 有时这个错误

( http://i.stack.imgur.com/quXMB.jpg ) http://i.stack.imgur.com/quXMB.jpg http://mahdedu.org/2.jpg

I want to download it and add it in laravel manually without using composer. 我想下载它并手动将其添加到laravel中,而不使用composer。

When you say "without using composer ", I'm going to assume you mean "without using composer for the download". 当您说“不使用composer ”时,我将假设您的意思是“不使用composer进行下载”。 With the following solution you'll still need to invoke a composer command, but its just to get the library auto-loading. 使用以下解决方案,您仍然需要调用composer命令,但这只是为了自动加载库。

First step is to find a folder that makes sense for storing your local copy of TCPDF. 第一步是找到一个文件夹,该文件夹对于存储TCPDF的本地副本很有意义。 I would recommend against using the vendor folder, because that folder is largely (solely?) managed by composer . 我建议不要使用vendor文件夹,因为该文件夹在很大程度上(唯一地?)由composer管理。 For the sake of demonstration, let's create a new folder called app/vendor . 为了演示,让我们创建一个名为app/vendor的新文件夹。 Not the best choice, I know, but this is just a demonstration of one possible solution. 我知道这不是最佳选择,但这只是一个可能解决方案的演示。 Download TCPDF, unzip it and move the resulting tcpdf folder into app/vendor (so you should end up with app/vendor/tcpdf ). 下载TCPDF,将其解压缩,然后将生成的tcpdf文件夹移至app/vendor (因此最终应使用app/vendor/tcpdf )。

Second step is to add this folder to the autoload section of composer.json , as follows: 第二步是将该文件夹添加到composer.json的autoload部分,如下所示:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/vendor/tcpdf" // <== HERE IT IS
    ]

Finally, run composer dump-autoload . 最后,运行composer dump-autoload

You should now be able to use the TCPDF library within your code without any external download dependencies. 现在,您应该可以在代码中使用TCPDF库,而无需任何外部下载依赖项。 I tested this solution on a clean copy of Laravel 4.1 and it worked fine. 我在干净的Laravel 4.1副本上测试了此解决方案,并且效果很好。

If anybody has a more appropriate suggestion as to the location of the tcpdf folder, please add a comment. 如果有人对tcpdf文件夹的位置有更合适的建议,请添加注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM