2016-04-14 54 views
0

我有一些代码,我正努力将“数据”从“发送数据到Zend partial视图助手”中分离出来。例如,即我要创建“仅仅是数据”,从我的数据功能,家长来电者如何重构代码以避免将部分ViewHelper的输出分配给另一部分ViewHelper的变量?

//contains no $this->partial(), deals only with accumulating data 
//that may or may not be used for partial later on 
$data = $this->getDataOnly(); 

//deals only with sending data to partial for rendering purposes 
$this->generatePartials($data); 

只返回数据在下面的代码我似乎都混合在一起。具体而言,我有一个partial作为我的数据的一部分,这就是我想要避免的。

// $modalData is an array accumulating data for Zend Partial View Helper 
// it already has some data, i.e. id, boolean vars 
foreach($modalData as $i => $value) 
{ 
    // here we are adding 'modalHtml' view helper variable 
    // which will contain HTML gotten from (another) partial 
    // Problem: I am not comfortable using a 'partial' as part of a parent 'partial' 
    // (which is further down in the code) 

    // what could've been "clean data only" generation is about to be 
    // polluted by stuffing a partial into it, mixing data and view 
    $modalData[$i]['modalHtml'] = $this->partial(
     "partial/product.phtml", 
     parent::getModalContentData($i) 
    ); 
} 

//here we are appending HTML produced from partialLoop, using $modalData 
$modalBoxesHtml .= $this->partialLoop("partial/modal_box.phtml", $modalData); 

问题:

我能避免我在哪里“馅的部分(这是HTML代码,而不是数据)直接进入的另一视图助手局部变量”的一部分? 我可以使用某种更好的更智能的构造,类似ViewModeladdChild

我想远离将“HTML块”分配给视图帮助变量并仅分配实际数据。这可以做到吗?

回答

0

我可能已经能够做什么,我寻求

我移动partial方法调用到partial/*.phtml文件本身

<div> 
    <?php 
    echo $this->partial("partial/product.phtml", $this->modalData); 
    ?>    
</div> 

我现在有嵌套的谐音。

我的数据变得嵌套过

foreach($modalData as $i => $value) 
    $modalData[$i]['modalHtml'] = parent::getModalContentData($i); 
相关问题