CodeIgniter:4.0.3 FPDF-错误类"FPDF"未找到 [英] CodeIgniter: 4.0.3 FPDF - error Class 'FPDF' not found

查看:105
本文介绍了CodeIgniter:4.0.3 FPDF-错误类"FPDF"未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用fpdf库从CodeIgniter:4.0.3生成PDF文档.我已将fpdf库复制到app/ThirdParty文件夹中.

I am trying to generate a PDF document from CodeIgniter: 4.0.3 using fpdf library. I have copied fpdf library in app/ThirdParty folder.

我已经在控制器的顶部添加了库引用.

I have included library reference at the top of controller like this.

    <?php namespace App\Controllers\Purchase;

     namespace App\ThirdParty\fpdf;

     use CodeIgniter\Controller;

     use FPDF;

我已经在控制器中创建了一个类,以扩展FPDF以包括这样的页眉和页脚.

I have created a class in the controller to extend FPDF to include header and footers like this.

    class PDF extends FPDF
    {

    
       function Header()
       {
       }
    
    }

我这样生成pdf.

       $pdf = new PDF();
       $pdf->AddPage();

运行应用程序时,出现此错误.

When I run the application, I get this error.

错误找不到"FPDF"类114类PDF扩展了FPDF

Error Class 'FPDF' not found 114 class PDF extends FPDF

该如何解决?

推荐答案

您应该检出fpdf lib中的任何名称空间.您似乎对它们和 use

You should checkout whatever your namespace in fpdf lib is. It looks like you're a bit confused about them and the use word

下面是一个有关如何加载 app/ThirdParty 文件夹下的lib的示例:

Here's an example on how to load a lib which is under the app/ThirdParty folder :

您的FPDF主类命名为 FPDF.php :

Your FPDF main class named FPDF.php :

<?php

// the path you need to follow to access your file
namespace App\ThirdParty;

class FPDF {
    
    public function __construct() {
        // do your things
    }
}

您的控制器名为 Foo.php :

<?php

namespace App\Controllers;

// the namespace of the lib file + its class name
use App\ThirdParty\FPDF;

class Foo extends \CodeIgniter\Controller {
    
    public function myPDF() {
        $pdf = new FPDF();
    }
}

这篇关于CodeIgniter:4.0.3 FPDF-错误类"FPDF"未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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