一般在操作 View 時,可能會有一些重複的結構需要render,這種狀況可以透過 View Helper 的 Partial 處理
使用方法
template.phtml (Partial 預設路徑會是在 application/views/scripts)
Thsi is Template
View
<?php echo $this->partial('template.phtml'); ?>
加入參數
template.phtml
<ul> <li>From: <?php echo $this->escape($this->from) ?></li> <li>Subject: <?php echo $this->escape($this->subject) ?></li> </ul>
View
<?php echo $this->partial('template.phtml', array( 'from' => 'Test', 'subject' => 'Zend' )); ?>
迴圈
template.phtml
<dt><?php echo $this->key ?></dt> <dd><?php echo $this->value ?></dd>
View
<?php $model = array( array('key' => 'Mammal', 'value' => 'Camel'), array('key' => 'Bird', 'value' => 'Penguin'), array('key' => 'Reptile', 'value' => 'Asp'), array('key' => 'Fish', 'value' => 'Flounder'), ); echo $this->partialLoop('template.phtml',$model); ?>