View previous topic :: View next topic |
Author |
Message |
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Tue Dec 23, 2003 4:08 pm Post subject: general structure |
|
|
hi everybody,
well i just made some tiny things with smarty and now im asking myself wich king of structure to take for a real project.
think of a website that has 6 or 7 main kategories with some static and some dynamic and some database driven content.
well, i first startet to drive the hole thing over one index.php and one index.tpl and let the logic decide which kategorie displays which header graphics and how the colors are and so on. fine, than i got those cashing problems because i drive the whole site over the index.php. shure, that can be solved but it seams this one-php-pages-does-the-whole-thing solution is not that cool.
ok, now i split the php-files and the templates to match the main kategories. so i can e.g. embed that header i need withod any logic, and the different parts of the page (static-html, database stuff, aso.) can be embeded without probs.
hmmm, i testet it for the first 3 kategories and encountered the many almost same template-, and php-files i´m using. much redundancies there are.
i think u got the point...which way to go?? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Mon Jan 05, 2004 9:04 am Post subject: |
|
|
i would like to know how you did the eidbop-approach with caching on.
heres the basic structure of mine:
index.php
<?php
require("smarty/setup.php");
$smarty = new Smarty;
//$smarty->caching = false;
$smarty->assign("item", $HTTP_GET_VARS['item']-1);
$smarty->display("index.tpl");
?>
index.tpl
{include file="header.tpl"}
{include file="navi.tpl"}
{include file="body.tpl"}
navi.tpl
...
<a href="{$smarty.server.PHP_SELF}?item=4">Navi 1</a>
<a href="{$smarty.server.PHP_SELF}?item=5">Navi 2</a>
...
when i use it with caching ON, the {$item} value is only parsed once, then i get it (no matter where i am) from the cache. if i turn caching OFF the value is processed correctly.
(wir können auch gerne deutsch sprechen ) |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jan 05, 2004 9:37 am Post subject: |
|
|
Read about Multiple Caches Per Page . Your "item" has to be part of the cache_id.
(aber wenn wir deutsch sprechen verstehen uns die anderen ja nicht ) |
|
Back to top |
|
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Mon Jan 05, 2004 10:00 am Post subject: |
|
|
that was easy...
$cache_id = $HTTP_GET_VARS['item'];
if(!$smarty->is_cached('index.tpl', $cache_id)) {
// no Cache
$smarty->assign("item", $HTTP_GET_VARS['item']);
}
$smarty->display("index.tpl", $cache_id);
thanks! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jan 05, 2004 11:23 am Post subject: |
|
|
yep, this should get you going. but you should always check input from outside ($HTTP_GET_VARS in your case) for sanity. check if the resulting item is valid before you use it as a cache_id to be safe. |
|
Back to top |
|
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Fri Jan 16, 2004 11:59 am Post subject: |
|
|
hey, can't i use $smarty.server.PHP_SELF in a plugin function? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Fri Jan 16, 2004 12:13 pm Post subject: |
|
|
well i know $_SERVER['PHP_SELF'] works, but whats the difference using $smarty.server.PHP_SELF and php reserved vars anyway? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Jan 16, 2004 12:19 pm Post subject: |
|
|
stellarid wrote: | well i know $_SERVER['PHP_SELF'] works, but whats the difference using $smarty.server.PHP_SELF and php reserved vars anyway? |
erm. the former is a php variable the latter is a smarty variable. |
|
Back to top |
|
stellarid Smarty Rookie
Joined: 23 Dec 2003 Posts: 6
|
Posted: Fri Jan 16, 2004 1:19 pm Post subject: |
|
|
shure..
i mean in using it within smarty when building a framework. |
|
Back to top |
|
|