Tutorial 7 : Change the library behaviour - neeftarah/odtphp GitHub Wiki

The purpose of this tutorial is to show how to change the behaviour of odtPHP. To do that, you just have to give to the constructor of the Odf class a second optional parameter.

The PHP code

<?php
require_once('../library/odf.php');

$config = array(
    'ZIP_PROXY'       => 'PhpZipProxy', // Make sure you have Zip extension loaded
    'DELIMITER_LEFT'  => '#', // Yan can also change delimiters
    'DELIMITER_RIGHT' => '#'
);

$odf = new odf("tutoriel7.odt", $config);

$odf->setVars('titre', 'PHP: Hypertext PreprocessorPHP: Hypertext Preprocessor');

$message = "PHP est un langage de scripts libre ...";

$odf->setVars('message', $message);
$odf->exportAsAttachedFile();
 
?>

Change the behaviour of odtPHP is very easy. you just have to give a configuration array for the second parameter of the Odf class constructor. The keys of this array are configuration names to modify : ZIP_PROXY, DELIMITER_LEFT and DELIMITER_RIGHT.

ZIP_PROXY is used to modify the proxy to use for handling Zip compression/decompression within odtPHP. By default, 'PclZip' is used. It consists of an interface with the PclZip library. You can also use 'PhpZipProxy'. In this case, odtPHP will directly use Zip extension from PHP. Note that you will have to activate this extension in your PHP configuration. Moreover, note that this extension is bugged since PHP 5.2.7.

DELIMITER_LEFT and DELIMITER_RIGHT are used to personalize delimiters of tags for the template. By default, these delimiters are braces : {}.

The OpenOffice model (tutoriel7.odt)

#titre#

#message#

Here, we have choosen to use the character # as delimiter of tags.

The result

tutorial odtPHP