Re:[BEGINNER] Question about caching
| From: | Luc Saint-Elie | Date: | Fri, 28 Dec 2001 21:59:04 +0000 |
| Subject: | Re:[BEGINNER] Question about caching | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2419@lists.php.net to get a copy of this message | ||
At 03:43 28/12/01 -0800, Brian E. Lozier wrote:
Brian,
First thanks a lot.. it works...
Excuse me if this question sounds stupid but I just discover caching and by the way I'm more an advanced webmaster than a real developer
If you're using exactly one template per page, you just use this: $tpl->display('yourtemplate.tpl', $REQUEST_URI);I works.... but I don't really get ho to apply is_cached() in my specific setup. ...... My setup is a little bit more complex. I've a main template (index.tpl) that is the skeleton of each page of the site, somehow corresponding to the canonical header/footer In fact my index.tpl has 3 zones, : header, footer and in the middle a 3 columns zone. Depending of values passed in the url (than can be raw navigation switch or user characteristic) the sub-templates included in index.tpl change. Index.tpl contains includes like {include file=$bloc1} le value of $bloc1 change according to url variables. In fact my typical index.php file starts like that : <?php session_start(); /***************************************************/
/* Smarty Template //***************************************************/ require("Smarty.class.php"); $smarty = new Smarty; $smarty->compile_check = false; $smarty->debugging = false; $smarty->caching = false; $smarty->assign("now", time()); /***************************************************/
/* Template selection */ /* Based on the argument passed in the url with */ /* the 'op' variable we get an array containing */ /* sub-templates to display *//***************************************************/ require('lib/template.php'); if (!isset($op)){ $op= 'vide'; } $menu = array(); $menu = getDisplay($op,$pay); $smarty->assign('bloc1',$menu['bloc1'] ); $smarty->assign('bloc2',$menu['bloc2'] ); $smarty->assign('bloc3',$menu['bloc3'] ); $smarty->assign('bloc4',$menu['bloc4'] ); $smarty->assign('bloc5',$menu['bloc5'] ); $smarty->assign('bloc6',$menu['bloc6'] ); $smarty->assign('centre',$menu['centre'] ); And my lib/template.php is like that : //:................. function getDisplay($op,$pay=NULL, $sup=NULL) { $display = array(); switch ($op) { case 'sorties' : $display['bloc1'] = 'bloc.soirees.diminsolite.tpl';
$display['bloc2'] = 'bloc.multisexualitesida.tpl';
$display['bloc3'] = 'bloc.enpromo.tpl';
$display['bloc4'] = 'bloc.association.tpl';
if ($pay == "y"){
$display['bloc5'] = 'bloc.pay.y.tpl';
}elseif ($pay == "n"){
display['bloc5'] = 'bloc.pay.n.tpl';
} else {
$display['bloc5'] = 'bloc.pay.how.sorties.tpl';
}
$display['bloc6'] = 'bloc.contacts.tpl';
$display['centre'] = 'general.sorties.tpl';
return $display;
break;
and so on....
Luc
If you're using exactly one template per page, you just use this: $tpl->display('yourtemplate.tpl', $REQUEST_URI); And it will display the cached page. But remember you need to go back and test to see if it's cached before performing all your db calls, action, etc. So you need: if(!$tpl->is_cached('yourtemplate.tpl', $REQUEST_URI)) {// do all your page logic here} $tpl->display('yourtemplate.tpl', $REQUEST_URI); The whole method seems to break as soon as you start using ->fetch(), though. Brian