PHP Classes
Icontem

File: use_get_example1.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  use_get_example1.php  
File: use_get_example1.php
Role: ???
Content type: text/plain
Description: Example of using the use_get() method w/ the default option
Class: Generalized CachedTemplate class
General Template Caching class
 

Contents

Class file image Download
<?php
/*
 * $Id: use_get_example1.php,v 1.1 2000/07/31 14:05:10 jesus Exp $
 */

// call this script: get_example1.php?title=Cool+Script

// based on the example using the FastTemplate class
// demonstrates the use of the use_get() method to append
// the GET query string to the named of the cached document

require "./class.FastTemplate.php3";
require "./class.FastTemplateAdaptor.php";
require "./class.CachedTemplate.php";

echo "<hr>QUERY_STRING: ".$GLOBALS["QUERY_STRING"]."<hr>";

$ftpl = new CachedTemplate();
$ftpl->init("./templates");

// use the QUERY_STRING in the cached filename
$ftpl->use_get();

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

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


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

// Otherwise process the page, 
// using the gtitle var passed as a GET query string
$ftpl->assign( array( TITLE => $gtitle) );

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

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

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

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

// get parsed document
$data = $ftpl->getParsedDoc();
echo $data;

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

// we write the file at the end so this
// operation will not be counted in the benchmark
$ftpl->write_to_cache($data);

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products