Ben kullanmak
$this->partialLoop('template.phtml', array(
'data' => $iterable,
'otherVariable' => $otherVariable
);
Warning & Edit:
Tamamen dürüst olmak gerekirse, ben bir hata yaptım. Ben teklif kod çalışmaz sanırım. Ben kısmi () yardımcısı için yanlış. Çünkü verecek kişinin sınıfının bu kısmı çalışmaz:
foreach ($model as $item) {
// increment the counter variable
$this->partialCounter++;
$content .= $this->partial($name, $module, $item);
}
Yerine "veri" tuşu tüm dizi üzerinde yineleme olacaktır. Nikolaus Dulgeridis D Teşekkür olduğuna işaret için: Ben cevap kabul edilebilir nasıl alamadım.
Atanan değişkenler mevcut değişkenleri ile çarpışır olmaz - böylece kısmi noktası görünümü örneği "temiz" oluşturur olduğundan bile $ this-> görünümü sayesinde herhangi bir ekstra veriyi açamazsınız.
Possible options
- Extend the view helper with methods to set custom variables
- Iterate the array and reformat it to
array(
array('data' => $item1, 'id' => 1, 'totalCount' => 10) ,
array('data' => $item2, 'id' => 2, 'totalCount' => 10) ,
array('data' => $item3, 'id' => 3, 'totalCount' => 10) ,
)
- Use Registry to store the values.
Zend_Registry::set('partialLoopCount', $count);
$this->partialLoop($viewScript, $data);
- Dump partialLoop and use partial() instead
Ben bu çözümü tercih ederim.
$count = count($data);
foreach ($data as $key => $value) {
echo $this->partial($viewScript, array('item' => $value, 'position' => $key, 'count' => $count));
}