【问题标题】:Codeigniter model Undefined propertyCodeigniter 模型未定义属性
【发布时间】:2012-03-29 10:03:06
【问题描述】:

我在控制器文件中有以下代码,用于检查后变量 pdf 并执行以下代码

if(isset($_POST['pdf']) && $_POST['pdf']=="pdf")
            {
                $this->load->model('voutput_model');
                $final_view = $data['frmReport'];
                $PDF_Name = "report.pdf";
                $this->votput_model->pdf($PDF_Name,$final_view);

            }

我在模型文件中有以下代码

class Voutput_model extends CI_Model{

    public function __construct()
    {
        parent::__construct();
        $this->CI = get_instance();
    }

    public function pdf($file_name,$filecontents){
        $this->pdf_path = $this->config->item('pdf_path');
        $this->load->library('htmltopdf/Html2fpdf');
        $file['Attach_path'] = $this->pdf_path.$file_name;
        $this->html2fpdf->generate_pdf($file['Attach_path'],$filecontents,'Y');
    }
}

当我执行代码时出现如下错误:

Severity: Notice
Message: Undefined property: Voutput::$Voutput_model
Filename: controllers/voutput.php
Fatal error: Call to a member function pdf() on a non-object in 
            C:\xampp\htdocs\asset\application\controllers\voutput.php 

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    使用前需要先加载模型。试试这个

     $this->load->model('votput_model');
     $this->votput_model->pdf($PDF_Name,$final_view);
    

    【讨论】:

    • 我已经在控制器中加载了这个
    • 我认为“generate_pdf”函数存在问题,如果我会卡在某个地方,我将首先对其进行调试,然后我将在此处发布此问题。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多