简体   繁体   中英

Echo an Table field on the View

sorry my english is bad, but lets get going. Im trying to make an view to print one table field but i dont know how to do it, i tried some examples but not sucess. Im calling the table field "descricao" from table "saidarecibo" leme show what im doing

on controller:

public function imprecibosaidaAction() {

  $id = (int) $this->params()->fromRoute('id', 0); $saidarecibo = $this->getTable('Admin\\Model\\Saidarecibo')->get($id); if ($id == 0) { throw new \\Exception("Código obrigatório"); } // Turn off the layout, ie only render the view script. $viewModel = new ViewModel(); $viewModel->setTerminal(true); return $viewModel; $view = new ViewModel(array( 'recibosaida' => $saidarecibo, )); return $view; 

}

and on the view:

<?php echo $saidarecibo['descricao']; ?>
<a style="margin-top:10px;" href="javascript:self.print()">IMPRIMIR</a>

Assuming that you get your table correctly, I would do something like this:

On your view imprecibosaida.phtml

<?php echo $this->saidarecibo; ?>

And on your controller imprecibosaidaAction(), after getting the table

$this->view->saidarecibo = $saidarecibo;

Anyway, I usually prefer to print my values one by one on the view, passing single values from the controller. So I'd want to get $saidarecibo as an array of rows (you can just fetch a query in standard Zend DB adapters or paginators), and refer to it like this

In the view:

<table>

    <?php foreach $this->saidarecibo as $item 
          {?>
          <tr>
          <?php echo '<td>'. $this->item['descricao'] .'</td>';?>
          </tr>
          <?php 
          } ?>
</table>

And on the controller you get the values of the table, and as before

 $this->view->saidarecibo = $saidarecibo;

Hope this helps ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM