Question

I want to to make a particular processing for the last item of a partialLoop, the documentation mention about $this->partialCounter but not the variable with the total number of items ...

<?php
if( $this->partialCounter == $mysteryvariable -1 ): 
?>

I am missing something I think ... cannot get my hand on that variable ...

Was it helpful?

Solution

Zend_Registy::set('PartialCount', count($iterable));
$this->partialLoop($script,$iterable);

and then in your view

$count = Zend_Registy::get('PartialCount'); 

Fast and crappy, but working. Other way would be to to extend PartialLoop helper ;)

OTHER TIPS

In order to get the total number of items, you will have to either extend Zend_View_Helper_PartialLoop to provide a method that returns the count of the iterable object being used by the PartialLoop.

Or, and I would say this is probably easier, just get the count of items in the object before you pass it into the PartialLoop since you have to pass either a Traversable object or an actual array into the PartialLoop helper and both implement support for count().

From the documentation:

<?php // partialLoop.phtml ?>
    <dt><?php echo $this->key ?></dt>
    <dd><?php echo $this->value ?></dd>


<?php // MyController.php

    public function indexAction()
    {
        $this->view->$model = array(
                                 array('key' => 'Mammal', 'value' => 'Camel'),
                                 array('key' => 'Bird', 'value' => 'Penguin'),
                                 array('key' => 'Reptile', 'value' => 'Asp'),
                                 array('key' => 'Fish', 'value' => 'Flounder'),
                              );

        $this->view->modelCount = count($this->view->model); 
    }

From index.phmtl

<p>Count: <?= $this->modelCount ?></p>
<dl>
<?php echo $this->partialLoop('partialLoop.phtml', $this->model) ?>
</dl>

I knew this is an old issue, but in ZF 1.12.1 this will be fixed. Till then there is a patch to get under following URL:

http://framework.zend.com/issues/browse/ZF-7151

Regards, Sascha

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top