Zend Framework How to list form elements using partialLoop

I am new to Zend Framework and not sure if this is possible.

I want to use partialloop to create a table with form fields.

I use this code in a 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 partial, I tried this:

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

And this one

  <!-- 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 table headers ( <tr><th>Cliente</th><th>Descripcion</th></tr> ), but nothing more. I know that partial processing is being processed because the first partial numbers equal to "=" are listed.

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

Thanks!

+4
source share
2 answers

The partialLoop function partialLoop able to handle 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(); ?> 
+6
source

Why not just use a decorator (HtmlTag)? I am using div

 $this->setElementDecorators(array( array('HtmlTag', array('tag' => 'div', 'class'=>'formRow')) )); 

but the table should not be much more complicated

0
source

All Articles