RE: [SMARTY] Why doesn't this work
| From: | Mark Priatel | Date: | Sun, 10 Aug 2003 05:55:58 +0000 |
| Subject: | RE: [SMARTY] Why doesn't this work | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-10024@lists.php.net to get a copy of this message | ||
> Does it mean that for a site that is very dynamic and keeps changing
> based on user selections I should not use a cache at all?
Yes and no. Caching in Smarty is very flexible. Every time you call
fetch or display on a template, you can control how the template is
cached by assigning one or more arbitrary cache ids to it:
$smarty->display('article.tpl', $article_id);
Often, the most common cache ID that people use is the current URI.
This works well if your web app's state is persisted through querystring
values. Eg:
http://yoursite.com/display_article.php?article_id=23&mode=detailed
then you can usually rely on:
$smarty->display('article.tpl', $_SERVER['REQUEST_URI'] );
in the case above, your template 'article.tpl' would be cached for each
different article ID, and for each different mode of display.
Generally, the more elements that go into controlling the dynamic
elements of your view, the more complicated your caching requirements
become, especially in user-centric sites -- consider a template which
displays an article in different ways based on a user's session state.
In any case Smarty provides a solution to almost any caching problem,
but often boils down to designing your application to be cache-friendly
to smarty; if performance is a really, really, big concern, I'd suggest
familiarizing yourself with how Smarty's cache works so that you adapt
your architecture accordingly.
You can read more about Smarty's caching features at:
http://smarty.php.net/manual/en/caching.php
------------------------
Mark Priatel
Iolog Web Communications
www.iolog.com
-----Original Message-----
From: Avi Schwartz [mailto:avi@CFFtechnologies.com]
Sent: Sunday, August 10, 2003 1:34 AM
To: smarty-general@lists.php.net
Subject: Re: [SMARTY] Why doesn't this work
Wow! That was quick and correct! Once I turned off caching it indeed
started showing the message. But the question now is what is going to
happen in real life once the code is in production? Am I not going to
have the same exact problem? Does it mean that for a site that is very
dynamic and keeps changing based on user selections I should not use a
cache at all?
Avi
On Sunday, Aug 10, 2003, at 00:29 America/Chicago, Mark Priatel wrote:
> I'd suggest turning off caching while you're in development.
>
> $this->caching = false;
>
> It's quite possible your displaying a cached page where you previously
> had no value in 'errorMessage' and even though it's getting assigned
to
> the template scope, smarty is just pulling up the cached page instead
> creating a new one.
>
> -mark
>
> ------------------------
> Mark Priatel
> Iolog Web Communications
> www.iolog.com
>
> -----Original Message-----
> From: Avi Schwartz [mailto:avi@CFFtechnologies.com]
> Sent: Sunday, August 10, 2003 1:19 AM
> To: smarty-general@lists.php.net
> Subject: [SMARTY] Why doesn't this work
>
> Hi,
>
> I am just starting with both smarty AND php so I assume this is
> something stupid I am doing but I need help figuring this out.
>
> The problem I am having is that the function process_form() in
test.php
> validates the input fields from the template's form and assigns an
> error message to $errorMessage.
> The popup debug console shows that the $errorMessage variable has the
> correct text, however when the template displays this variable it has
> no value so XX is displayed. What I am trying to figure out is what
> happened to the value of the $errorMessage variable.
>
> Thanks,
> Avi
>
> -- setup.php--
>
> // load Smarty library
> require_once('smarty/Smarty.class.php');
> require_once('DB.php');
>
> class Smarty_test extends Smarty {
> var $db;
>
> function Smarty_test() {
> // Class Constructor. These automatically get
> set with each new
> instance.
> $this->Smarty();
> $this->template_dir =
> '/srv/www/smarty_templates/';
> $this->compile_dir =
> '/srv/www/smarty_templates_c/';
> $this->config_dir = '/srv/www/smarty_configs/';
> $this->cache_dir = '/srv/www/smarty_cache/';
> $this->caching = true;
> $this->debugging = true;
> $this->assign('app_name','Test');
>
> $this->$db =
> DB::connect("pgsql://user:password@server/database");
> if (DB::iserror($this->$db)) {
> die($this->$db->getMessage());
> }
> }
> }
>
>
> -- test.php
>
> require('/srv/www/smarty_includes/setup.php');
>
> $smarty = new smarty_test();
>
> if (isset($_POST['step']) && ('step1' ==
> $_POST['step'])) {
> process_form();
> }
>
> $smarty->display(test.tpl');
>
> function process_form() {
> global $smarty;
>
> $field1 = trim($_POST['field1]);
> $field2 = trim($_POST['field2']);
>
> if (strlen($field1) == 0 || strlen($field2) == 0) {
> $smarty->assign('errorMessage', 'Both fields are
> required.');
> return;
> }
> }
>
>
> -- test.tpl
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
> <head>
> <title>Test</title>
> </head>
>
> <body>
> X{$errorMessage}X
> </body>
> </html>
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php