Zend framework2 在何处设置Zend2局部视图';谁的数据?

Zend framework2 在何处设置Zend2局部视图';谁的数据?,zend-framework2,partial-views,Zend Framework2,Partial Views,让我们假设我的视图显示为: <?php echo $this->partial( 'site/testimonials/partial.phtml', array() ); ?> <?php 对于此类任务,我认为最好使用视图帮助器 内部Module.phpclass: <?php use Zend\View\Model\ViewModel; public function getViewHelperConfig() { return ar

让我们假设我的视图显示为:

<?php 
    echo $this->partial( 'site/testimonials/partial.phtml', array() ); 
?>
<?php


对于此类任务,我认为最好使用视图帮助器

内部
Module.php
class:

<?php

use Zend\View\Model\ViewModel;

public function getViewHelperConfig()
{
    return array(
        'most_recent_testimonials' => function($helperPluginManager){
            $serviceLocator = $helperPluginManager->getServiceLocator();

            $view = new ViewModel();
            $view->setTerminal(true);
            $view->setTemplate('site/testimonials/partial.phtml');

            /*
             * There you may get all data you need using $serviceLocator
             */

            // inject data into template
            $view->setVariables(array(
                ...
            );

            // render template
            $template_rendered =
                $serviceLocator ->get('viewrenderer')
                ->render($view);

            return $template_rendered;
        }
    );
}

<?php echo $this->most_recent_testimonials(); ?>