Search code examples
zend-frameworktreeviewpartialview-helperszend-view

treeview with viewhelpers and partialLoop


I tried with the partialLoop viewhelper. It doesn't work I will try to explain it properly. In my view script I want to show the information of an event (Ribaveranstaltungen), that works. For each of the events I want to show the documents (Ribadocs). I thought this partialLoop thing could be a good idea. A bit of trouble I had with binding the data to the view inside my controller because of that I create the data in the view, I'm not happy with this, but I didn't find another solution for the moment. It might be part of the problem.

Here is my index view script:

<?php 
$veranstaltung=array();
$dokument=array();
$i=1;
$veran=new Application_Model_DbTable_Ribaveranstaltungen();
$documents = new Application_Model_DbTable_Ribadocs();

$veranstaltung=$veran->fetchAll();
foreach($veranstaltung as $v) : 
    $dokument=$documents->getDocumentveranstaltung1($v->id);?>

    <tr>
        <td class="row_<?PHP echo $i % 2;?>"><?php echo $v->veranstaltung;?></td>
    </tr>
        <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->partialLoop('/helpers/_docs-row.phtml', $dokument);?></td>
    <?php   

    $i=$i+1;
endforeach; ?>

and here my partialhelper:

<?php 
$i=1;
if ($dokument != NULL)
{?>
    <tr>
    <td class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->docid;?></td>
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->veranstaltung;?></td>
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->typ;?></td>
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->bezeichnung;?></td> 
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->quelle;?></td>
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->bemerkung;?></td>
    <td  class="row_<?PHP echo $i % 2;?>"><?php echo $dokument->pfad;?></td>
    </tr>
<?php 
$i=$i+1;
} ?>

I have several questions because I know I should bind the data in the controller: Why doesn't the code for the partial work? If it is because I didn't bind the data to the view ($this), how can I manage this, because the data changes for each event. (constraint: veranstaltung 1- n documents). Last one, is it right, that this partialLoop does the look automatically, like shows all data in object?


Solution

  • If you want to print the contents of data passed to your partial loop, I think you need to use $this->docid, and so on and not $dokument->docid. Or, you can do this so you can access the members as $this->dokument->docid

    <?php echo $this->partialLoop('/helpers/_docs-row.phtml', array('dokument' => $dokument));?>