Login   Register  
PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  CachedFastTemplate  >  test.php  >  Download  
File: test.php
Role: ???
Content type: text/plain
Description: Simple script showing the use of the CachedFastTemplate class
Class: CachedFastTemplate
Simple class extending CDI's Fastemplate Class
Author: By
Last change:
Date: 14 years ago
Size: 1,551 bytes
 

Contents

Class file image Download
<?php
// This test file is a simple modification of a
// sample file include in FastTemplate

require ("./class.FastTemplate.php3");
require ("./class.CachedFastTemplate.php");

$tpl = new CachedFastTemplate("./templates");

// for benchmarking
$start = $tpl->utime();

$filename = "yipeee.html";
// if the filename is empty, the class will use PHP_SELF

// the templates are distributed w/FastTemplate
// we need this definition first, so the new logic can
// detect if the templates have changed.
$tpl->define(
    array(
        main    => "main.tpl",
        table   => "table.tpl",
        row     => "row.tpl"
    )
);


// Check if we can send the cached file
if ($tpl->valid_cache_file($filename)) {
    echo "<B>FROM CACHE</B>\n<BR>";
    $tpl->read_from_cache($filename);
    $end = $tpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "Completed in $runtime miliseconds<BR>\n";
    exit;
}

// Otherwise process the page
$tpl->assign( array( TITLE => "FastTemplate Test") );

for ($n=1; $n <= 3; $n++)
{
    $Number = $n;
    $BigNum = $n*10;

    $tpl->assign(
        array(
            NUMBER      =>  $Number,
            BIG_NUMBER  =>  $BigNum
        )
    );

    $tpl->parse(ROWS,".row");
}

$tpl->parse(MAIN, array("table","main"));

$data = $tpl->fetch();
$tpl->write_to_cache($filename, $data);

$tpl->FastPrint();

// for benchmarking
$end = $tpl->utime();
$runtime = ($end - $start) * 1000;
echo "Completed in $runtime miliseconds<BR>\n";
exit;

?>