【发布时间】:2016-07-20 15:23:38
【问题描述】:
我的控制器类中有一个方法,它正在执行一些操作等。现在我需要从生成 PDF 的同一控制器调用另一个方法。
但是当我调用第二种方法时,第一种方法没有完成?
我这样调用第二种方法,所以这条线以下的任何内容都不会完成:
$this->generate_certificate($course_id);
我错过了什么吗?我是否需要以不妨碍第一种方法继续执行的方式调用它。
第一种方法,相关位|:
else if($progress == 'c') {
// the course is complete and the user has pressed the complete button
// on the final page of the course
// set course as complete in the db, set completed date, set due to next due
// as defined in course date
// get todays date
$todays_date = date("Y-m-d");
// add specified months on for next due
$months = $course_object[0]->renewal_period;
$due_date = date('Y-m-d', strtotime($todays_date . ' + ' . $months .' months'));
$training_data = array();
$training_data['user_id'] = $user_id;
$training_data['course_id'] = $course_id;
$training_data['due'] = $due_date;
$this->training_model->set_course_complete($training_data);
$this->generate_certificate($course_id);
//certificate generated, redirect to training dashboard
$view_data = array(
'page_title' => 'Training Dashboard',
'user_courses' => $this->training_model->get_user_courses($user_id),
);
$this->session->set_flashdata('msg', 'You have successfully completed this course!');
$this->load->view('training/training_dashboard',$view_data);
}
生成PDF方法:
private function generate_certificate($course_id) {
$this->load->model('org_model');
$this->load->model('user_model');
// get todays date
$todays_date = date('d F Y');
// get currently logged in user details
$user_id = $this->session->userdata('user_id');
$user_object = $this->user_model->get_user($user_id);
$users_name = $user_object[0]->first_name . " " . $user_object[0]->last_name;
// course data
$course_object = $this->training_model->get_course_data($course_id);
// get org name
$org_id = $this->session->userdata('org_id');
$org_name_object = $this->org_model->get_org_name($org_id);
$org_name = $org_name_object[0]->org_name;
$html=" // I've removed this as its large, but works perfectly // ";
//this the the PDF filename that user will get to download
$pdfFilePath = "Certificate.pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
【问题讨论】:
-
你能把你的两种方法的代码给我们吗?
-
添加到原帖
-
你从哪里得到
$course_id? -
它被送入第一个方法的开始。第一种方法运行良好,第二种方法运行良好,我已经分别测试过,它们工作正常。只有当我将调用添加到第二种方法时,第一种方法才不会完成。为什么它会停止该方法的其余部分运行?
-
可以给
$org_name_object的var_dumo吗
标签: php codeigniter