|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sammydafish Smarty Rookie
Joined: 10 Nov 2003 Posts: 13 Location: Upstate, NY
|
Posted: Mon Nov 10, 2003 2:54 pm Post subject: Can Smarty do this???? |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
sammydafish Smarty Rookie
Joined: 10 Nov 2003 Posts: 13 Location: Upstate, NY
|
Posted: Wed Nov 12, 2003 5:21 pm Post subject: |
|
|
Thanks a lot man. That's exactly what I was looking for
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 _________________ - Anthony |
|
Back to top |
|
|
|
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
|