Alternatively, the correct controller could be chosen based on the intended
usage. If a repeat block doesn't use the value of "last" this doesn't even
apply. If "last" is being used, pre-fetching may be an option to get the
intended value of count()

Actually this could apply to other functions as well, such as "first",
"odd", "even", etc. If you're not going to use it, why store it inside the
compiled code? ;-)

On Feb 2, 2008 7:15 PM, Iván -DrSlump- Montes <[EMAIL PROTECTED]>
wrote:

> As far as I know a PDOStatement object implements the Countable
> interface for the number of columns not the rows. This means that the
> repeat controller will give a 'wrong' value for the 'end' attribute in
> the loop.
>
> To solve it either you need to modify the RepeatController to detect
> PDOStatement objects and fetch all the rows at instantiation time and
> count them, or you manually preprocess the statement and convert it to
> an array or an iterable object before using it.
>
> Another option would be to rewrite the Repeat attribute to only work
> with and Iterator object (using ArrayObject for arrays) and change the
> logic it uses to detect the last item in the set by pre-fetching the
> next item at the end of the loop and checking its validity.
>
> Iván
>
> On Feb 1, 2008 2:12 PM, Julien Fredon <[EMAIL PROTECTED]>
> 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"
> >  I changed the following code (RepeatController line 58) :
> >
> >          if ($source instanceof IteratorAggregate) $source =
> > $source->getIterator();
> >          else if (!is_array($source) && !($source instanceof Iterator))
> > $source = array();
> >
> >  with
> >
> >          if ($source instanceof IteratorAggregate) $source =
> > $source->getIterator();
> >          else if (!is_array($source) && !($source instanceof Iterator)
> &&
> > !($source instanceof Traversable)) $source = array();
> >
> >  but i'm not sure that it's the good or the best solution.
> >
> >
> >
> > --
> >
> >
> >
> >  Julien
> >
> > _______________________________________________
> > PHPTAL mailing list
> > PHPTAL@lists.motion-twin.com
> > http://lists.motion-twin.com/mailman/listinfo/phptal
> >
> >
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>



-- 
--
Tjerk
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to