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

general structure

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


Joined: 23 Dec 2003
Posts: 6

PostPosted: Tue Dec 23, 2003 4:08 pm    Post subject: general structure Reply with quote

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
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Dec 23, 2003 4:45 pm    Post subject: Reply with quote

i like the everything-is-driven-by-one-file-approach and don't have any caching-issues.

also maybe something like jtm's setup (described in http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1471 ) is interesting for you.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stellarid
Smarty Rookie


Joined: 23 Dec 2003
Posts: 6

PostPosted: Mon Jan 05, 2004 9:04 am    Post subject: Reply with quote

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 Wink)
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Jan 05, 2004 9:37 am    Post subject: Reply with quote

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 Smile )
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stellarid
Smarty Rookie


Joined: 23 Dec 2003
Posts: 6

PostPosted: Mon Jan 05, 2004 10:00 am    Post subject: Reply with quote

that was easy...Wink

$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
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Jan 05, 2004 11:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
stellarid
Smarty Rookie


Joined: 23 Dec 2003
Posts: 6

PostPosted: Fri Jan 16, 2004 11:59 am    Post subject: Reply with quote

hey, can't i use $smarty.server.PHP_SELF in a plugin function?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Jan 16, 2004 12:07 pm    Post subject: Reply with quote

stellarid wrote:
hey, can't i use $smarty.server.PHP_SELF in a plugin function?


you can, but it's called differently in php. see: http://php.dpnet/manual/en/reserved.variables.php#reserved.variables.server
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stellarid
Smarty Rookie


Joined: 23 Dec 2003
Posts: 6

PostPosted: Fri Jan 16, 2004 12:13 pm    Post subject: Reply with quote

well i know $_SERVER['PHP_SELF'] works, but whats the difference using $smarty.server.PHP_SELF and php reserved vars anyway?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Jan 16, 2004 12:19 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
stellarid
Smarty Rookie


Joined: 23 Dec 2003
Posts: 6

PostPosted: Fri Jan 16, 2004 1:19 pm    Post subject: Reply with quote

shure..Wink
i mean in using it within smarty when building a framework.
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