簡體   English   中英

在視圖上回顯表字段

[英]Echo an Table field on the View

抱歉,我的英語不好,但讓我們開始吧。 我試圖做一個視圖來打印一個表字段,但我不知道該怎么做,我嘗試了一些例子,但沒有成功。 我從表“ saidarecibo” leme中調用表字段“ descricao”表明我在做什么

在控制器上:

公共功能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; 

}

並在視圖上:

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

假設您正確獲取了表格,我將執行以下操作:

在您看來imprecibosaida.phtml

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

在獲取表后,在您的控制器上imprecibosaidaAction()

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

無論如何,我通常更喜歡在視圖上一一打印我的值,並從控制器傳遞單個值。 因此,我想將$ saidarecibo作為行的數組(您可以在標准Zend DB適配器或分頁器中獲取查詢),並像這樣引用它

在視圖中:

<table>

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

並在控制器上獲得表的值,和以前一樣

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

希望這可以幫助 ;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM