7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @version $Id: PartialLoop.php 16222 2009-06-21 19:55:20Z thomas $
20 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_View_Helper_Partial */
24 require_once 'Zend/View/Helper/Partial.php';
27 * Helper for rendering a template fragment in its own variable scope; iterates
28 * over data provided and renders for each iteration.
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_View_Helper_PartialLoop
extends Zend_View_Helper_Partial
39 * Marker to where the pointer is at in the loop
42 protected $partialCounter = 0;
45 * Renders a template fragment within a variable scope distinct from the
46 * calling View object.
48 * If no arguments are provided, returns object instance.
50 * @param string $name Name of view script
51 * @param string|array $module If $model is empty, and $module is an array,
52 * these are the variables to populate in the
53 * view. Otherwise, the module in which the
55 * @param array $model Variables to populate in the view
58 public function partialLoop($name = null, $module = null, $model = null)
60 if (0 == func_num_args()) {
64 if ((null === $model) && (null !== $module)) {
70 && (!$model instanceof Traversable
)
71 && (is_object($model) && !method_exists($model, 'toArray'))
73 require_once 'Zend/View/Helper/Partial/Exception.php';
74 throw new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data');
78 && (!$model instanceof Traversable
)
79 && method_exists($model, 'toArray')
81 $model = $model->toArray();
85 // reset the counter if it's call again
86 $this->partialCounter
= 0;
87 foreach ($model as $item) {
88 // increment the counter variable
89 $this->partialCounter++
;
91 $content .= $this->partial($name, $module, $item);