views:

310

answers:

1

Hi everybody

I'm new to Zend Framework and not sure if this this posible.

I want to use partialloop for creating a table with the form fields.

I'm using this code in the view:

<!-- code in views/scripts/request/edit.phtml -->

<table cellpadding='0' cellspacing='0'>
    <tr>
        <th>Cliente</th>
        <th>Descripcion</th>
    </tr>        
    <?php echo $this->partialLoop('partials/_solicitud-row.phtml', $this->form); ?>        
</table>

And in the partial i tried this:

<!-- code in views/scripts/partials/_solicitud-row.phtml -->
<tr>    
<td><?php  echo $this->key . "=" . $this->value; ?></td>

</tr>

And this

 <!-- code in views/scripts/partials/_solicitud-row.phtml -->
<tr>     
<td><?php  echo $this->Descripcion; ?></td>
<td><?php  echo $this->cliente; ?></td>
<td><?php  echo $this->FechaHoraCreada; ?></td>
<td><?php  echo $this->Monto; ?></td>

</tr>

Using this I get the titles of the table (<tr><th>Cliente</th><th>Descripcion</th></tr>) but nothing more. I know the partial is processed because using the first partial the equals "=" are listed.

Does it make sense what I'm doing? is there a way to access the form elements? I tried other options like $this->getElement.., but didn't work

Thanks!

+4  A: 

The partialLoop function is able to process your form elements, but you need to back up a bit:

  <!-- code in views/scripts/request/edit.phtml -->
  <?php
    $model = array();
    foreach ( $this->form as $element ) {
      // include the $element itself, instead of the
      // $element public properties (which are few)
      $model[] = array('element' => $element);
    }
  ?>
  <?php echo $this->partialLoop('partials/_solicitud-row.phtml', $model); ?>

.

  <!-- code in views/scripts/partials/_solicitud-row.phtml -->
  <?php  echo $this->element->getName(). "=" . $this->element->getValue(); ?>
Derek Illchuk
GREAT!, this works just fine!Sorry I don't have enough reputation to vote your answer....
Alex Angelico
I voted for you Alejandro.
powtac
+1 :) really great answer
SM