2016-07-20 5 views
1

컨트롤러 클래스에 메서드를 몇 가지 작업을 수행하고 있습니다. 이제는 PDF를 생성하는 동일한 컨트롤러에서 다른 메서드를 호출해야합니다.동일한 컨트롤러 내에서 codeigniter 메서드 호출

하지만 두 번째 방법을 호출하면 첫 번째 방법이 완료되지 않습니까?

는 그래서 같은 두 번째 방법을 호출, 그래서이 라인 아래에 아무것도 완료 나던 :

$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"); 
} 
+0

두 가지 방법을 알려주시겠습니까? – elddenmedio

+0

원래 게시물에 추가됨 – frobak

+0

어디에서'$ course_id'를 얻었습니까? – elddenmedio

답변

0

당신은 PDF를 생성 모델의 방법을 만들어야합니다. 모델에서 다른 모델 메서드를 호출 할 수 있으므로 generate_certificate 메서드를 새 모델에 배치 할 수 있습니다. 그런 다음 해당 모델을 컨트롤러에로드하고 해당 메서드를 호출합니다.

실행을 중단하지 않습니다.

PDF 만 생성하는 단일 메서드가 필요한 경우 모델 메서드도 호출하십시오.

관련 문제