0

在一个视图中将数据插入 3 个不同表的最佳方法是什么,例如:

富视图:

添加卡片,添加玩家,目标。

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

1 回答 1

0

您可以继续使用表类,因为您可以使用 joomla 内置函数执行存储和更新功能。阅读更多

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; 
    }

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

于 2012-11-01T14:33:54.130 回答