2013-12-16 70 views
0

的那一刻我想下面的表保存:需要保存數據

http://img5.fotos-hochladen.net/uploads/tabelle1k6xegf4tm.jpg

只有-fields當我點擊下方的藍色按鈕進行保存表。 我的問題:我是joomla的新手,不知道如何保存這個。 我使用正確的類嗎? 有沒有可能通過表級解決這個問題? 也許有人可以給我一個組件,在這樣的事情解決? 或者可以給我正確的代碼樣本?

在這裏您可以找到我做了什麼:

class TippspielModelTippview extends JModelList 
    { 
     protected function getListQuery() 
     { 
      //Erstelle ein neues Query-Objekt 
      $db= JFactory::getDbo(); 
      $query= $db->getQuery(true); 

      //Hole alle Daten 
      $query->select('t2.id, t2.date, t2.goalsteam1, t2.goalsteam2, t1a.team AS mannschaft1, t1b.team AS mannschaft2'); 
      $query->from('#__tournament AS t2'); 
      $query->join('left','#__team AS t1a ON t2.team1 = t1a.id'); 
      $query->join('left','#__team AS t1b ON t2.team2 = t1b.id'); 
      $query->order('date'); 

      //und liefere es zurück 
      return $query;   
     } 

    } 

class TippspielViewTippview extends JViewLegacy 
    { 
     //Variable zur Speicherung aller Teams 
     protected $pages; 
     protected $games; 

     function display($tpl = null) 
     { 
      //Hole Daten aus dem Modul 
      $this->games = $this->get('Items'); 
      $this->pages = $this->get('Pagination'); 

      //Layout aktivieren und ausgeben 
      parent::display($tpl); 
     } 
    } 

表單

<form action="<?php echo JRoute::_('index.php?option=com_tippspiel&view=tippview'); ?>" method= "post" name="adminForm" id="adminForm"> 
    <?php echo $this->pages->getLimitBox(); ?> 
    <table class="table table-striped"> 
     <thead> 
      <tr> 
       <th>Heim</th> 
       <th>Gast</th> 
       <th>Spielbeginn</th> 
       <th>Tipp</th> 
       <th>Ergebnis</th> 
       <th>Punkte</th> 
      </tr> 
     </thead> 
     <tbody> 
      <?php foreach($this->games as $i => $game): ?> 
       <tr> 
        <td><?php echo $game->mannschaft1; ?></td> 
        <td><?php echo $game->mannschaft2; ?></td> 
        <td><?php echo JHtml::date($game->date); ?></td> 
        <td>Tipp</td> 
        <td><?php echo $game->goalsteam1; ?> : <?php echo $game->goalsteam2; ?></td> 
        <td>Punkte</td> 
       </tr> 
      <?php endforeach; ?> 
     </tbody> 

回答

4

JModelList是上市項目。

要顯示創建/編輯表單並保存項目,您需要使用JModelAdmin。

但是,您試圖保存的不是「一個項目」,因此您可以使用JModelLegacy。在這裏使用JModelList並不是一個大問題,它仍然有效,但我更喜歡JModelLegacy。

將您的值發佈到控制器,控制器獲取值並保存,保存後將其重定向到另一個視圖或相同的視圖。