Can a Zend Framework export help me with partialLoops?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Can a Zend Framework export help me with partialLoops?

Post by joshmaker »

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:

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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Can a Zend Framework export help me with partialLoops?

Post by Eran »

You can not persist variables between iterations, that's part of how the partialLoop helper works. However, it does have a built in iteration counter, called partialCounter, which you can access like any other view parameter.
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Re: Can a Zend Framework export help me with partialLoops?

Post by joshmaker »

For my project, I need to save some values beyond simple iterations, but I think I found a way to do it that works from within the partialLoop:

Code: Select all

$this->getHelper('PartialLoop')->view->myVar = $value;
Post Reply