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

Can Smarty do this????

 
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
sammydafish
Smarty Rookie


Joined: 10 Nov 2003
Posts: 13
Location: Upstate, NY

PostPosted: Mon Nov 10, 2003 2:54 pm    Post subject: Can Smarty do this???? Reply with quote

Please help me clarify something here. I've searched through the docs and the forum and even tried some tests, but I can't seem to find the answer.

I'm building a relatively simple site with managed content. The content is stored in a mySQL database and is relatively static. Once created, it will probably only change every few weeks or months. The main reason that I'm looking at Smarty is because if it's caching capabilities. The more I look at it though, I'm not sure that it will do what I need. What I'd like to do is cache the content generated from the mySQL data. Take this example.


I have

test.php
Code:

<?php
$smarty = new Smarty;

// get content from database
$dbcnx = mysql_connect("mySQLserver", "user", "password");
mysql_select_db("mydatabase");
$row = mysql_fetch_array(mysql_query("SELECT title, content FROM table"));

$smarty->assign("title",$row['title']);
$smarty->assign("content",$row['content']);


// display template
$smarty->display('test.tpl');

?>


and test.tpl
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
   <title>{$title}</title>
</head>

<body>
{$content}

</body>
</html>


This caches a page that looks like this:
Code:

<?php /* Smarty version 2.6.0-RC2, created on 2003-11-10 09:49:24
         compiled from test.tpl */ ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
   <title><?php echo $this->_tpl_vars['title']; ?>
</title>
</head>

<body>
<?php echo $this->_tpl_vars['content']; ?>


</body>
</html>


But I need it to cache the data from the database also. Since the database content will change so rarely, there's no need for me to suffer the performance overhead of hitting the database with every request. I need this information cached. So how can I do this? Ideally, I'd want the cached page to look like this:
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
   <title>Title From Table</title>
</head>

<body>
Content From Table

</body>
</html>


Can Smarty do this? If so, where can I get more info on how?
_________________
- Anthony
Back to top
View user's profile Send private message Visit poster's website AIM Address
messju
Administrator


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

PostPosted: Mon Nov 10, 2003 3:26 pm    Post subject: Reply with quote

what you showed as the "cached page" is actually the compiled-page. the cached page is what you want and contains no php-code.

set $smarty->caching=true and read http://smarty.php.net/manual/en/caching.multiple.caches.php , i'm sure you'll need it.

(EDIT: and use http://smarty.php.net/manual/en/api.is.cached.php Smile )
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sammydafish
Smarty Rookie


Joined: 10 Nov 2003
Posts: 13
Location: Upstate, NY

PostPosted: Wed Nov 12, 2003 5:21 pm    Post subject: Reply with quote

Thanks a lot man. That's exactly what I was looking for Very Happy

This definatly should be added to the crash course on the Smarty home page. This feature is very awesome, and the sole reason I'm trying to use Smarty in my app .... verry cool thing Cool
_________________
- Anthony
Back to top
View user's profile Send private message Visit poster's website AIM Address
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