给出以下手册:在此处输入链接说明
当我知道控制器中使用的captureTo(例如" <?php echo $this->article ?>
")时,很容易拥有一个子视图并回显它,但是当我动态生成视图模型并将它们分配给动态生成的captureTo时,我可以做类似的事情吗addChild()函数:
foreach ($studentEvaluations as $studEval) {
$studEvalId = $studEval->getEvalId();
$formViewModel = $this->buildStudentEvaluationViewModel($studEval);
$viewModel->addChild($formViewModel, $studEvalId);
}
我尝试了以下方法,但它不起作用:
<?php foreach ($this->viewModel()->getCurrent()->getIterator() as $studId => $studEval) : ?>
<tr>
<td><?php echo $this->escapeHtml($studEval->fname); ?></td>
<td><?php echo $this->escapeHtml($studEval->lname); ?></td>
<td><?php echo $this->escapeHtml($studEval->formName); ?></td>
<td><?php echo $this->escapeHtml($studEval->supdated); ?></td>
<td><?php echo $this->escapeHtml($studEval->screated); ?></td>
<td>
<button class="btn btn-primary btn-lg"
data-toggle="modal"
data-target="#myModal<?php echo $studId; ?>"
data-loading-text="Loading..."> Edit
</button>
<!-- Modal -->
<div class="modal fade" id="myModal<?php echo $studId; ?>" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<p>
<!-- HERE ->>>>>>>>> --> <?php echo $studEval ?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
编辑 1
当我尝试以这种方式输出视图时,这是一个错误:
Catchable fatal error: Object of class Zend'View'Model'ViewModel could not be converted to string in C:'dev'projects'OnlineFieldEvaluation'module'OnlineFieldEvaluation'view'online-field-evaluation'online-field-evaluation'test3.phtml on line 62
我找到了方法。这只是我在PHP方面的知识运气:
<?php foreach ($this->viewModel()->getCurrent()->getChildren() as $studEval) : ?>
<tr>
<td><?php echo $this->escapeHtml($studEval->fname); ?></td>
<td><?php echo $this->escapeHtml($studEval->lname); ?></td>
<td><?php echo $this->escapeHtml($studEval->formName); ?></td>
<td><?php echo $this->escapeHtml($studEval->supdated); ?></td>
<td><?php echo $this->escapeHtml($studEval->screated); ?></td>
<td>
<button class="btn btn-primary btn-lg"
data-toggle="modal"
data-target="#myModal<?php echo $studEval->captureTo(); ?>"
data-loading-text="Loading...">
Edit <?php echo $studEval->captureTo(); ?>
</button>
<!-- Modal -->
<div class="modal hide fade" id="myModal<?php echo $studEval->captureTo(); ?>" tabindex="-1"
role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<p>
<?php
echo $this->{$studEval->captureTo()};
?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>