I have this problem when trying to generate a file from PHPWord template processor where I have this code...
<?php
require_once '../vendor/autoload.php';
$num_written = 0;
class Processor{
private $templateProcessor;
private $objWriter;
function __construct($template){
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template);
}
function create_document_from_template($formdata){
global $num_written;
$num_written++;
$name = "Receipt".$num_written.".docx";
//Notice: Undefined variable: templateProcessor
$templateProcessor->setValue('name',$formdata["company-name"]);
$templateProcessor->setValue('address',$formdata["company-address"]);
$templateProcessor->setValue('city',$formdata["company-city"]);
$templateProcessor->setValue('can_province',$formdata["company-can-province"]);
$templateProcessor->setValue('postal_code',$formdata["company-postal-code"]);
$templateProcessor->setValue('phone_number',$formdata["company-phone-number"]);
$templateProcessor->setValue('email',$formdata["company-email"]);
$templateProcessor->setValue('website',$formdata["company-website"]);
$templateProcessor->setValue('letter_signature_name',$formdata["company-letter-signature-name"]);
$templateProcessor->setValue('letter_signature_title',$formdata["company-letter-signature-title"]);
$templateProcessor->setValue('letter_text',$formdata["company-letter-text"]);
$templateProcessor->setValue('receipt_signature_name',$formdata["company-receipt-signature-name"]);
$templateProcessor->setValue('charity_number',$formdata["company-charity-number"]);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($templateProcessor, 'Word2007');
$link_to_save = "../submission/docxs_to_send/".$name;
$objWriter->save($link_to_save);
return $name;
}
}
?>
Where $template is the name of my docx that is in the same directory as my php files
I get the following error: Notice: Undefined variable: templateProcessor
I can't find any documentation on this particular problem, why is that?
Aucun commentaire:
Enregistrer un commentaire