Persistant variables with PartialLoops joshmaker

For programming and general questions on Zend Framework
Post Reply
joshmaker
Posts: 4
Joined: Mon Apr 20, 2009 11:48 pm

Persistant variables with PartialLoops joshmaker

Post by joshmaker » Mon Apr 20, 2009 11:51 pm

I am using a partialLoop and I am looking for a way to have a variable persist across iterations of the partial loop.

Here is a simple example of the sort of thing that I would like to do inside of my partial:

Code: Select all

<li>
  <?= $this->value // Value from an array, this part works great ?>
  <? if( !isset($count) ) $count = 1;
   else ++$count // Persistent value ?>
  <?= $count ?>
</li>
So in this example I would like the $count variable to increase in value with each iteration of the loop. However, what happens instead is that the $count is reset to 1 each time. This could be great for alternating row colors, making the first X number of items in a list stand out, etc.

Can anyone help me out with this?

Thanks,

Josh

joshmaker
Posts: 4
Joined: Mon Apr 20, 2009 11:48 pm

Re: Persistant variables with PartialLoops joshmaker

Post by joshmaker » Tue Apr 21, 2009 3:01 pm

OK, I figured it out.

You can assign persistent variables in partialLoop this way:

Code: Select all

$this->getHelper('PartialLoop')->view->myVar = 'whatever';

Post Reply