2015-04-21 18 views
1

我只是試圖熟悉Zend Framework 2.我嘗試了每個組件的不同可能性。現在我正在用viewscripts進行測試,以獲得更好的細節。麻煩的是,我不明白如何挑選正確的記錄來刪除。我總是第一個。從視圖腳本中挑選出正確的記錄

我有這樣的HTML中viewscript:

<table> 
    <tr> 
     <th>Tag</th> 
     <th>Datum</th> 
     <th>Zeit</th> 
     <th>Thema</th> 
     <th></th> 
    </tr> 
    <?php 
     $lodge = new Application_Model_DbTable_Arbeitskalender(); 
     $i=1; 
     foreach($this->aktermine as $termin) :  
    ?>  
    <tr> 
     <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->nr);?></td> 
     <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->day($termin->datum);?></td> 
     <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->date($termin->datum);?></td> 
     <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->zeit);?></td> 
     <td class="row_<?PHP echo $i % 2;?>"><?php echo $this->escape($termin->thema);?></td> 
     <td class="row_<?PHP echo $i % 2;?>"> 
      <a href="<?php echo $this->url(array('controller'=>'aktermine', 'action'=>'edit', 'kopfnr'=>$termin->kopfnr));?>"> 
      <img src="Images/Icons/edit.jpg" width="16" height="16" title="Termin editieren" /></a> 
     </td> 
     <td class="row_<?PHP echo $i % 2;?>"> 
      <a href="<?php echo $this->url(array('controller'=>'aktermine', 'action'=>'delete', 'kopfnr'=>$termin->kopfnr));?>"> 
      <img src="Images/Icons/minus.jpg" width="16" height="16" title="Termin entfernen"/></a> 
     </td> 
     <td class="row_<?PHP echo $i % 2;?>"> 
      <a href="<?php echo $this->url(array('controller'=>'aktermine', 'action'=>'add', 'kopfnr'=>$termin->kopfnr));?>"> 
      <img src="Images/Icons/plus.jpg" width="16" height="16" title="neuer Termin"/></a> 
     </td> 
    </tr> 
    <?php 
     $i=$i+1; 
     endforeach; 
    ?> 

如果我用我的刪除操作,我總是得到的第一條記錄。我如何選擇正確的記錄,這是如何工作的?我有建議,那是因爲圖標。在另一個觀點,我有鏈接,而它的工作。那麼如何使用圖標?這裏也是我的刪除行爲:

public function deleteAction() 
{ 
    if ($this->getRequest()->isPost()) { 
     $del = $this->getRequest()->getPost('del'); 
     if ($del == 'Yes') { 
      $nr = $this->getRequest()->getPost('nr'); 
      $aktermine = new Application_Model_DbTable_Aktermine(); 
      $aktermine->deleteTermine($nr); 
     } 
     $urlOptions = array('controller'=>'aktermine', 'action'=>'index');   
     //redirector = Seitenaufruf controller, action 
     $this->_helper->redirector->gotoRoute($urlOptions); 
    } else { 
     $nr = $this->_getParam('kopfnr', 0); 
     $aktermine = new Application_Model_DbTable_Aktermine(); 
     $this->view->aktermine = $aktermine->getTermine($nr); 
    } 
} 
+0

如果你剛開始使用ZF2,你的第一個項目應該是[教程應用](https://zf2.readthedocs.org/en/latest/user-guide/overview.html#the-tutorial-application) 。它[詳細回答你的問題](https://zf2.readthedocs.org/en/latest/user-guide/forms-and-actions.html#deleting-an-album)。 – AlexP

+0

謝謝我已經這樣做了,但現在我正在嘗試不同的可能性來獲得相同的結果 –

回答

0

問題解決了。我在我的get函數中有一個(複製/粘貼)錯誤,我使用了外鍵而不是主鍵。