2012-11-01 13 views
0

什麼是插入的數據在一個視圖中3頁不同的表例如最好的辦法3個表:插入數據到一個視圖的Joomla

fooview:

添加卡,加的球員,進球。

  1. 使用插入查詢?
  2. 使用3個不同的表類?
  3. 還是你有更好的辦法?

回答

0

您可以繼續使用表類,因爲您可以使用joomla內置函數執行存儲和更新功能。 Read more

function store() 
    { 
     //Get post data 
     $this->_data = $this->getPostData(); 

     $row = &$this->getTable('model_name'); 


     if (!$row->bind($this->_data)) 
     { 
      $this->setError($this->_db->getErrorMsg());   
      return false; 
     } 


     if (!$row->check()) 
     {   
     $this->setError($this->_db->getErrorMsg()); 
     return false; 
     } 


     if (!$row->store()) 
     { 
     $this->setError($this->_db->getErrorMsg()); 
     return false; 
     }  
     $new_id = $this->_db->insertId(); 

     if($new_id > 0) 
      $this->_data->id = $new_id; 

     return true; 
    } 

設置後的數據如下

function getPostData() 
    { 
     $this->_data->id  = JRequest::getVar('id', 0, 'POST'); 
     $this->_data->field1 = JRequest::getVar('field1', '', 'POST'); 
     $this->_data->field2 = JRequest::getVar('field2', '', 'POST'); 
     return $this->_data; 
    } 

,如果您有任何疑問請詢問。

+1

@Dasum你能再次解釋你的3張桌子在哪裏? –

+0

它們是您的組件中存在的joomla表。請參閱閱讀更多鏈接 – Techie

+1

是的,但是您的代碼僅將數據保存到一個表中,而問題是關於插入到三個不同的表中。 –

相關問題