PHP Classes

File: use_vars_example.php

Recommend this page to a friend!
  Classes of Jesus M. Castagnetto   Generalized CachedTemplate class   use_vars_example.php   Download  
File: use_vars_example.php
Role: ???
Content type: text/plain
Description: example of the user_vars() method
Class: Generalized CachedTemplate class
General Template Caching class
Author: By
Last change:
Date: 23 years ago
Size: 2,357 bytes
 

Contents

Class file image Download
<?php /* * $Id: use_vars_example.php,v 1.3 2000/07/31 14:38:35 jesus Exp $ */ // call this script: use_vars_example.php?title=Cool+Script // based on the example using the FastTemplate class // demonstrates the use of the use_vars() method to use // a set of variable/value pairs when caching require "./class.FastTemplate.php3"; require "./class.FastTemplateAdaptor.php"; require "./class.CachedTemplate.php"; $ftpl = new CachedTemplate(); $ftpl->init("./templates"); $critical_vars = array ( "template_number" => 1, "database_name" => "mydb", "document_title" => $title ); echo "<hr>\n<pre>\ncritical_vars:\n"; var_dump($critical_vars); echo "\n</pre>\n"; echo "if 'title' is NULL, you forgot to pass that var in the URL, something like: http://yousite.com/path/to/use_vars_example.php?title=Cool+script<hr>"; // use the $critical_vars when caching, store them into // a var data file $ftpl->use_vars($critical_vars,"store"); // 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); ?>