Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向CodeIgniter添加自定义库_Php_Codeigniter_Fpdf - Fatal编程技术网

Php 向CodeIgniter添加自定义库

Php 向CodeIgniter添加自定义库,php,codeigniter,fpdf,Php,Codeigniter,Fpdf,我在CodeIgniter中有以下类声明: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); if (session_status()==PHP_SESSION_NONE){ session_start(); } require_once(APPPATH.'libraries/fpdf/fpdf17/fpdf.php'); class Fpdf { var $ci;

我在CodeIgniter中有以下类声明:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (session_status()==PHP_SESSION_NONE){
    session_start();
}

require_once(APPPATH.'libraries/fpdf/fpdf17/fpdf.php');

class Fpdf {
    var $ci;
    var $pdf;
    public function __construct(){
        $this->ci =& get_instance();
        $this->pdf = new FPDF();
    }

    public function t(){
        echo 'Orayt!';
    }

    public function generateResume(){
        $this->pdf->AddPage();
        $u_id = $this->session->userdata('user_id');
        $this->db->where('user_id',$u_id);
        $data = $this->db->get('user');
        // Header
        foreach($data->result() as $row){
            $mName = $row->middle_name; $name = $row->first_name . ' ' . $mName[0] . '. ' . $row->last_name;
            $this->pdf->Cell(0,0,$name,0,1);
        }
        $this->pdf->Output();
    }

    public function testPDF(){
        $this->pdf->AddPage();
        $this->pdf->SetFont('Arial','B',16);
        $this->pdf->Cell(40,10,'Hello World!');
        $this->pdf->Output();
    }
}

?>

我的问题是,当我使用
$this->load->library('fpdf')将其加载到控制器中时它不加载

有人能帮我找到如何纠正这个错误吗?提前感谢。

用户指南:

检查您的文件名,使用相同的名称作为类名和文件名

我认为如果您捕获或复制您的错误,它将帮助我们,为什么您说它不会加载

 public function __construct(){
        $this->ci =& get_instance();
        $this->pdf = new FPDF();
    }
使用此代码,$his->ci通过引用分配允许您使用原始CodeIgniter对象,而不是创建其副本

因此,如果您想调用或使用CI librari,您必须喜欢此示例

$data=$this->db->get('user'); cange收件人: $data=$this->ci->-db->get('user')

用户指南:

检查您的文件名,使用相同的名称作为类名和文件名

我认为如果您捕获或复制您的错误,它将帮助我们,为什么您说它不会加载

 public function __construct(){
        $this->ci =& get_instance();
        $this->pdf = new FPDF();
    }
使用此代码,$his->ci通过引用分配允许您使用原始CodeIgniter对象,而不是创建其副本

因此,如果您想调用或使用CI librari,您必须喜欢此示例

$data=$this->db->get('user'); cange收件人:
$data=$this->ci->-db->get('user')

如果您不加载CI_控制器,是否可以使用此选项

$ci = & get_instance();
$ci->load->library('name');

如果不加载CI_控制器,可能会使用此选项

$ci = & get_instance();
$ci->load->library('name');

它不会输出任何错误。我只是无法加载库在控制器调用库时尝试添加代码,或者复制方法并粘贴到此处,以便我们知道您需要什么。这是我用于加载库的代码部分:
public function uu-construct(){
parent::u-construct();
$This->load->library('facebook'));
$this->load->library('fpdf'))
您只是加载库而没有使用它?我正在使用它。我创建了一个调用库中函数的公共函数,它不会输出任何错误。我只是无法加载库尝试在控制器调用库时添加代码,或者复制您的方法并粘贴到此处,以便我们知道您需要什么。这是我用来加载库的代码:
public function\uu-construct(){
parent::\uu-construct();
$this->load->library('facebook');
$this->load->library('fpdf'))
您只是加载了库而没有使用它?我正在使用它。我创建了一个公共函数,调用库中的函数,或者在autoloader中添加库。phpIt在执行建议的步骤后仍然无法加载,先生。或者在autoloader中添加库。phpIt在执行建议的步骤后仍然无法加载,先生。