Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Frustrated at Caching

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
darkshadeau
Smarty n00b


Joined: 04 Nov 2003
Posts: 2
Location: Michigan, USA

PostPosted: Tue Nov 04, 2003 4:36 am    Post subject: Frustrated at Caching Reply with quote

I am new to smarty and am having a difficult time with caching. Whenever I revisit a particular page I want to pass certain variables based on an in-else statement in PHP. The problem is that the page works well the first time it is visited after I save the template, but every time after that it uses the values that were passed in the first visit to the page.

Here's the template:

Code:
{* Smarty Template *}
{* Include the header file *}
{include file="head.tpl"}
   <form name="regInfo" action="pword.php" method="post">
   <div id="userInfo">
      <div id="formInputs">
         <div id="labels">
            <p class="label"><label for="fname" title="First Name"{$fnameRed}>First Name:</label></p>
            <p class="label"><label for="lname" title="Last Name"{$lnameRed}>Last Name:</label></p>
            <p class="label"><label for="email" title="Email Address"{$emailRed}>Email Address:</label></p>
            <p class="label"><label for="month" title="Birthday">Birthday (month/day/year):</label></p>
            <p class="label"><label for="username" title="Preferred Username"{$usernameRed}>Preferred Username:</label></p>
         </div>
         <div id="inputs">
            <p class="input"><span><input type="text" name="fname" size="20" id="fname" value="{$fname}"></span></p>
            <p class="input"><span><input type="text" name="lname" size="20" id="lname" value="{$lname}"></span></p>
            <p class="input"><span><input type="text" name="email" size="20" id="email" value="{$email}"></span></p>
            <p class="input"><span><input type="text" name="month" size="2" id="month" value="{$month}"> / <input type="text" name="day" size="2" id="day" value="{$day}"> / <input type="text" name="year" size="4" id="year" value="{$year}"></span></p>
            <p class="input"><span><input type="text" name="username" size="20" id="username" value="{$username}"></span></p>
         </div>
      </div>
      <div id="buttons">
         <span><input type="submit" value="Next >>"></span>
      </div>
   </div>
   </form>
{include file="foot.tpl"}

Here's the PHP page that calls the template:

[php:1:b12f778773]<?php
session_start();

require('smarty.php');

$smarty = new Page;

if (isset($_SESSION["redo"])){ //If the user is returning to this page, check the session variables
if ($_SESSION["fname"] == "0"){
$smarty->assign("fnameRed", " style=\"color: red;\"");
$smarty->assign("fname", "");
}else{
$smarty->assign("fnameRed", "");
$smarty->assign("fname", $_SESSION["fname"]);
}

if ($_SESSION["lname"] == "0"){
$smarty->assign("lnameRed", " style=\"color: red;\"");
$smarty->assign("lname", "");
}else{
$smarty->assign("lnameRed", "");
$smarty->assign("lname", $_SESSION['lname']);
}

if ($_SESSION["email"] == "0"){
$smarty->assign("emailRed", " style=\"color: red;\"");
$smarty->assign("email", "");
}else{
$smarty->assign("emailRed", "");
$smarty->assign("email", $_SESSION['email']);
}

if ($_SESSION["username"] == "0"){
$smarty->assign("usernameRed", " style=\"color: red;\"");
$smarty->assign("username", "");
}else{
$smarty->assign("usernameRed", "");
$smarty->assign("username", $_SESSION['username']);
}
}

$smarty->assign("title", "New User Information");
$smarty->display("reg_info.tpl");
?>[/php:1:b12f778773]
And finally, here's smarty.php:

Code:
//load the smarty library
require('Smarty.class.php');

class Page extends Smarty{
   function Page(){ //Class constructor
      $this->Smarty();
      
      $this->template_dir="/templates/";
      $this->compile_dir="/templates_c/";
      $this->config_dir="/configs/";
      $this->cache_dir="/cache/";
      
      $this->caching = true;
   }
}

If I turn off caching it works fine. Any idea why it is behaving like this?

Thanks,
-Ron
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 04, 2003 5:08 am    Post subject: Reply with quote

read http://smarty.php.net/manual/en/caching.multiple.caches.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website
darkshadeau
Smarty n00b


Joined: 04 Nov 2003
Posts: 2
Location: Michigan, USA

PostPosted: Tue Nov 04, 2003 1:56 pm    Post subject: Reply with quote

I saw that portion of the manual, but didn't think it was appropriate for my situation. Why, you ask? Because part of the content which is to be displayed will be data that the user has input during a previous visit to the page. There will be no way to know ahead of time what that data will be.

The way I interpret "multiple caches" is that you have a finite number of possibilities in which a page can be displayed. Each of those possibilities is cached. In my case, there is an infinite, unpredictable number possibilities because the end user inputs some of the content (first name, last name, etc).

Basically, here is my question. With caching turned on, is smarty able to display dynamic content (say, from a database) which may change with every call to a page? I mean, I have a template and I fill that template with data from a user input or a database.

With caching enabled, it looks like smarty is only designed to display content which is either static or predictable (using "multiple chaches").

Like I said, I'm new to smarty. So, if I am way off on this, please let me know and set me straight.

Thanks,
Ron
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 04, 2003 2:47 pm    Post subject: Reply with quote

there is {insert} ( http://smarty.php.net/manual/en/language.function.insert.php ) to emit little portions of uncached content into the template. but you don't have real template-capabilities in your inserts.

of course you can trick around and generate cache-ids from your user's input. but if your content is really dynamic (like user-input as you said) you may be best of not caching it at all.

smarty-2.6.0 will give the possibility to except portions of a template from the caching. but this feature is not mature yet and i don't recommend using it for novice users.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Nov 04, 2003 8:02 pm    Post subject: Reply with quote

As an aside: I think it is a mistake to worry about static content on pages that accept user input/editing as by definition, you are looking at a page that requires refreshing anyhow.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP