On 29-07-2010 at 16:09:52 Klederson Bueno <kleder...@klederson.com> wrote:

I have this framework ( www.phpburn.com ) and while i do: $obj->fetch() it
returns true or false until while ends... however repeat works more as a
foreach and then i cant use this... how can i work with repeat working as a while ?

You can wrap it in an iterator:

class WhileIterator implements Iterator
{
    protected $current, $obj;

    function __construct($obj)
    {
       $this->obj = $obj;
    }

    function next()
    {
$this->current = $this->obj->fetch() ? you_get_next_object_here() : false;
    }

    function current()
    {
        return $this->current;
    }

    function key()
    {
        return 'implement if you care';
    }

    function valid()
    {
        return !!$this->current;
    }

    function rewind()
    {
        $this->next(); // loads first object
    }
}


You can also make custom expression modifier:

function phptal_tales_while($expr, $nothrow)
{
        return 'new WhileIterator('.phptal_tale($expr,$nothrow).')';
}

and then use tal:repeat="x while:obj"

--
regards, Kornel

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

Reply via email to