Amptools.Net

simplify your life.

Fun Times with Partial Loops in Zend Framework

No Gravatar

While working with the Zend Framework and partial loops, I ran into a few issues. One was not getting the data to load, which was easily solved after looking at . Make sure you set the object key in the controller for the partial loop. The other issue of trying to pass local variables into the partial loop took time to see there was really no current answer without extending or creating a new helper, or the evil global.

PHP

// in the action method
global $otherVariable;
$otherVariable = "should be the same through each iteration";
$this->view->partialLoop()->setObjectKey('model');
$this->view->paginator = Zend_Paginator::factory($array); //etc

// in the view
<?= $this->partialLoop('path/to/_partial.phtml', $this->paginator) ?>

// in the _partial.phtml
<?php
      $model = $this->model
      global $otherVariable; // just seems so hackish to have to do this.
?>

I have already added a task to to extend the Partial Loop Helper to overcome the lack of the ability to pass in local variables to the partial loop.

Tags: , ,

Thursday, June 11th, 2009 Blog Comments