Smarty looping w/ interator
| From: | Ted Suzman | Date: | Tue, 15 Jul 2003 19:09:18 +0000 |
| Subject: | Smarty looping w/ interator | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-1722@lists.php.net to get a copy of this message | ||
=========The Scenario=========
A developer want to print the contents of a database result set using a
Smarty section loop.
=========The Problem=========
Currently, it seems necessary to collect the contents of the result set into
an array and assign() the array to Smarty. "Buffering" the result set in
this manner requires a (relatively) large amount of memory: the entire
result set has to be loaded into an array.
=========A Possible Solution=========
Perhaps {section} and {foreach} can use an interator to loop through
whatever is sent to them, be it a result set, an array, or a directory
handle. In the case of the above scenario, a developer can just assign the
results of their query to Smarty directly. {section} and {foreach} can call
on an implementation of of the interator to do their job. This is completely
transparent to the designer.
As with any abstraction, this solution has some overhead. However, Smarty
{section} and {foreach} loops are very often used to print result sets --
using an interator here may be worth it.
I like the Eclipse iterator design by Vincent Oostindië at
http://www.students.cs.uu.nl/people/voostind/eclipse/.
Comments appreciated!
Ted Suzman
ted@suzman.net