Following with the repeat discussion I've refactored the repeat controller to add some Zope features missing from it. I've also added support for PHP internal objects implementing Traversable (like PDO) by traversing the object at instantiation time and storing all the results in a temporary array. I think this is a good trade off, if someone has special needs which are not suited by this approach he/she can wrap the traversable object with a specialized iterator.
The summary of the changes is: - Refactored to work only with SPL iterators (to simplify the code) - Arrays are wraped with ArrayIterator - Traversable objects are fetched at once and stored in an ArrayIterator - Added support for string iteration - Added support for 'letter' and 'roman' properties - Added support for grouping 'first' and 'last' properties - Most properties are computed as needed The only concern I have is that wrapping native arrays with ArrayIterator could affect performance. Although I haven't noticed any noticeable slow downs in my tests. I've attached the modified file to this mail hoping they can make it to the official branch.If they are used in the distribution I'll contribute some unit tests to cover the new functionality. PHPTAL/RepeatController.php PHPTAL/Php/Attribute/TAL/Repeat.php cheers, Ivan On Feb 3, 2008 1:25 PM, Kornel Lesiński <[EMAIL PROTECTED]> wrote: > On 01.02.2008, at 13:12, Julien Fredon wrote: > > > Hello phptal users, > > > > I have a problem with PHPTAL and PDO (www.php.net/pdo) when i use > > tal:repeat. > > PHPTAL_RepeatController seems angry with PDOStatement. > > > > PDOStatement is not "Iterator" but it's "Traversable" > > > That's the problem indeed. Traversable interface doesn't even offer > methods for returning current key and PDOStatement doesn't count total > number of rows at all. > > I've changed SVN version of PHPTAL to be less picky about what it > iterates and use keys obtained from foreach() instead of getting them > via interfaces or array_keys(). This allows basic iteration of > PDOStatement, DOMNodeList, etc. > > I'll think about supporting it better (which might require > introspection of template code to check if repeat/last, etc. are > used), but for now, if you need all repeat properties, my suggestion > is to use PDOStatement::fetchAll(). > > -- > regards, Kornel > > > > > > _______________________________________________ > PHPTAL mailing list > PHPTAL@lists.motion-twin.com > http://lists.motion-twin.com/mailman/listinfo/phptal >
RepeatController.php
Description: Binary data
Repeat.php
Description: Binary data
_______________________________________________ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal