0

您好,当我想循环我的信息时,我遇到了 phpword 库的问题

    // Education Foreach
$get_education = $this->db->query("SELECT * FROM `member_edu` WHERE Memberid='".$user_id."'");
foreach ($get_education->result() as $edu_row){
    $edu_json    = json_decode($edu_row->edu_details);
    $college     = $edu_json->College_name;
    $University  = $edu_json->University_name;
    $Degree      = $edu_json->Degree_name;
    $Grade       = $edu_json->Grade;
    $Special     = $edu_json->Speciality;
    $EduFrom     = $edu_json->From;
    $EduTo       = $edu_json->To;
    //// Values for loop in .docx file
    $document->cloneRow('rowEdu', $get_education->num_rows());
    $document->setValue('rowEdu#1', $college);
    $document->setValue('rowUniversity#1', $University);
    $document->setValue('rowDegree#1', $Degree);
    $document->setValue('rowGrade#1', $Grade);
    $document->setValue('rowSpeciality#1', $Special);
    $document->setValue('rowEdufrom#1', $EduFrom);
    $document->setValue('rowEduto#1', $EduTo);
}

这是我的代码,当member_edu有一个记录一切正常时,当我添加新教育时,循环出现错误。

错误代码:

Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 

'Can not clone row, template variable not found or variable contains markup.' in C:\xampp\htdocs\icareer\application\third_party\phpword\Template.php:186 Stack trace:
#0 C:\xampp\htdocs\icareer\application\views\resume\preview_view.php(59): PhpOffice\PhpWord\Template->cloneRow('rowEdu', 2)
#1 C:\xampp\htdocs\icareer\system\core\Loader.php(833): include('C:\xampp\htdocs...')
#2 C:\xampp\htdocs\icareer\system\core\Loader.php(419): CI_Loader->_ci_load(Array)
#3 C:\xampp\htdocs\icareer\application\controllers\ci_resume.php(722): CI_Loader->view('resume/preview_...', Array)
#4 [internal function]: CI_Resume->preview()
#5 C:\xampp\htdocs\icareer\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array)
#6 C:\xampp\htdocs\icareer\index.php(202): require_once('C:\xampp\htdocs...') #7 {main} thrown in C:\xampp\htdocs\icareer\application\third_party\phpword\Template.php on line 186

我不知道我能做什么这是第一次在 PHP 单词库中工作有人可以帮助我吗?

4

1 回答 1

1

您好,我自己找到了解决问题的方法谢谢您的帮助:)

而这个正确的代码。

  // Education Foreach
  $get_education = $this->db->query("SELECT * FROM `member_edu` WHERE Memberid='".$user_id."' ORDER BY `member_edu`.`edu_id` DESC");
  $document->cloneRow('rowEdu', $get_education->num_rows());
  $i=1;
  foreach ($get_education->result() as $edu_row){
      $edu_json    = json_decode($edu_row->edu_details);
      // Values for loop in .docx file
      $document->setValue('rowEdu#'.$i, $edu_json->College_name);
      $document->setValue('rowUniversity#'.$i, $edu_json->University_name);
      $document->setValue('rowDegree#'.$i, $edu_json->Degree_name);
      $document->setValue('rowGrade#'.$i, $edu_json->Grade);
      $document->setValue('rowSpeciality#'.$i, $edu_json->Speciality);
      foreach ($countries as $key => $country) {
        if ($key == $edu_json->Cuntry){
          $document->setValue('rowCountry#'.$i,$country);
        }
      }
      $document->setValue('rowEdufrom#'.$i, $edu_json->From);
      $document->setValue('rowEduto#'.$i, $edu_json->To);
      $i++;
  }
于 2014-07-20T21:12:18.693 回答