RE: [SMARTY-DEV] feature request
| From: | Peter Billen | Date: | Mon, 05 Jan 2004 17:52:46 +0000 |
| Subject: | RE: [SMARTY-DEV] feature request | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2029@lists.php.net to get a copy of this message | ||
Thanks for sharing your thoughts.
Indeed, I would also query the whole news item from the database. But some
of the questions is: how far would you go. You can't "predict" what the
template may need in the next lines:
- Do you also query the author (usually a JOIN with another table, say
"users") of the news item?
- Do you also query the comments (usually a JOIN ...) of the news item?
- Do you ...
If you answer yes on one of those questions, and it turns out the template
doesn't need it after all: overhead, you queried too much (and a join is
very expensive)
If you answer no on one of those questions, and it turns out the template
needed it, you have to query the database again, and usually combining two
queries into a JOIN of the 2 tables is much faster (yes ofcourse there are
exceptions)
So I think it may become very complex to realize such system on a efficient
way. I personally think this is the reason why you need caching, so the
overhead caused by redundant queries is not that high. However this approach
may turn out to be very difficult to implements (in my opinion, caching is
difficult on big sites).
Maybe it's not a good idea after all?
Regards,
Peter
-----Original Message-----
From: Mark Rogers [mailto:mark@quarella.co.uk]
Sent: maandag 5 januari 2004 18:29
To: 'Smarty Dev'
Subject: Re: [SMARTY-DEV] feature request
> Although there are some big issues:
>
> [...] - To avoid having redundant calls, some way of
> caching has to be implemented, but the code becomes
> more complicated.
I don't see a need for caching as such. The first time any (say) "news"
field is used, I'd pull the whole news article from the database, and assign
all the relevant vars. If there were no references to the news article in
the template, one query saved. If there are several, then it's still only
one query. The overhead from reading multiple vars and storing the results
when only one is needed is minor compared with the potential for saving a
complete query.
I personally think that the idea for having a function called whenever a
variable is first accessed which is undefined is a good one.
I am thinking, amongst other things, of how one could rewrite a CMS system
like *Nuke using Smarty templates. One of the key requirements would be the
ability to put any module I wanted anywhere in the template, but I wouldn't
want the code for (say) a voting module called unless I put the module on
the page. Putting the module into a custom function moves the presentation
of the module into the code, not in the template, which completely goes
against the code separation principle.
One alternative which comes to mind is an assign_by_func() method, ie:
[news.html]
function get_news() {
...
return $news;
}
$smarty->assign_by_func('news', 'get_news');
[news.tpl]
{$news.id} {$news.author}
--
Mark Rogers,
More Solutions Ltd :: Tel: 0845 45 89 555
--
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php