PHPWord код не работает, чтобы отредактировать шаблон и сохранить как новый файл

Я работаю над страницей, которая ведет учет всех данных и документов сотрудников в компании, часть ее функции - создание идентификационных карт, с которой я борюсь.

Я скачал PHP Word, сначала установив компоновщик и используя его для установки библиотеки PHPWord в корневой каталог проекта (где находятся страницы php), и он установил следующие файлы и папки:

-composer.lock -composer.json -vendor (это папка, содержащая всю библиотеку)

Подпапки и файлы "vendor": -autoload.php -composer (папка) -pclzip (папка) -phpoffice (папка) -zendframework (папка)

Я предположил, что это было все, что нужно было сделать для его установки, поэтому я продолжил добавлять код, проблема в том, что он не работает... вот код, я добавил комментарии, чтобы объяснить дальше:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    require_once 'conector_superadmin.php';
    $link = connect($conn);

    //Retrieving the id number sent via url to get the employee number
    $idSelectedEmployee = $_GET['SelectedEmployee'];

    //Data taken from small form with extra information for the ID Card
    $idType = $_POST['idType'];
    $ValidFrom = $_POST['ValidFrom'];
    $ExpiresOn = $_POST['ExpiresOn'];

    //Retrieving employee's information from "employees" table in db
    $sql = "SELECT * FROM employees WHERE idEmployee = '$idSelectedEmployee'";
    $result = mysqli_query($link, $sql);
    while($row = mysqli_fetch_array($result)){
        $FullName = $row['FullName'];
        $Position = $row['Position'];
        $EmployeeNum = $row['EmployeeNum'];
        $BloodType = $row['BloodType'];
        $Alergies = $row['Alergies'];
        $PhoneNum = $row['PhoneNum'];
    }

    //The company uses two kinds of id cards, so i use these conditionals to get the type from a “select” field, it does work, i tested it
    if($idType == "Plastic"){
        //This code inside however is what isn’t working at all, it won't do anything despite taking this code from their template
        include_once 'Sample_Header.php';

        $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('IDCards/Templates/ID_TEST.docx');

        //I am using in the docx file the “${Variable}” format as the template and other documentation explains

        $templateProcessor->setValue('EmployeeName', $FullName);
        $templateProcessor->setValue('PhoneNum', $PhoneNum);
        $templateProcessor->setValue('BloodType', $BloodType);
        $templateProcessor->setValue('Alergies', $Alergies);
        $templateProcessor->setValue('EmployeeNum', $EmployeeNum);
        $templateProcessor->setValue('Position', $Position);
        $templateProcessor->setValue('ValidFrom', $ValidFrom);
        $templateProcessor->setValue('ExpiresOn', $ExpiresOn);

        $templateProcessor->saveAs('IDCards/PlasticID.docx');

    }

    if($idType == "Paper"){
        //Still empty
    }

    //I created this table to insert the data taken from the “employees’ table, just for the purpose of testing if all the information was retrieved correctly, needless to say, it works fine
    $CredencialQuery = "INSERT INTO `idCards` (`idID`, `FullName`, `PhoneNum`, `BloodType`, `Alergies`, `EmployeeNum`, `Position`, `ValidFrom`, `ExpiresOn`, `idType`) VALUES (NULL, '$FullName', '$PhoneNum', '$BloodType', '$Alergies', '$EmployeeNum', '$Position', '$ValidFrom', '$ExpiresOn', '$idType');";

    mysqli_query($link, $CredencialQuery);

}
?>

Так что да, я понял, что сама проблема может быть в коде PHPWord, либо что-то в моем коде неверно, либо библиотека не установлена ​​должным образом, я попытался запустить сам шаблон php, чтобы проверить, работает ли этот шаблон, но он тоже не работает

0 ответов

Другие вопросы по тегам