在一个joomla视图上将数据插入3个表

时间:2012-11-01 13:51:34

标签: mysql joomla

在一个视图中向3个不同的表插入数据的最佳方法是:

fooview:

添加牌,添加玩家,进球。

  1. 使用插入查询?
  2. 使用3种不同的表类?
  3. 或者你有更好的方法?

1 个答案:

答案 0 :(得分: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; 
    }

如果您有任何疑问,请询问。