Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

php - Codeigniter model Undefined property

i have following code in the controller file which check for post varible pdf and execute following code

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);

            }

I have following code in model file

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');
    }
}

while i am executing the code i am getting error as below:

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:xampphtdocsassetapplicationcontrollersvoutput.php 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to load model before use . Try this

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...