2

如何在一个视图中显示 3 个表中的数据,因为使用 JTable 我只能显示绑定到该 JTable 的数据,请帮我解决这个问题。

到目前为止我的代码(不工作)在模型中:

public function getEntireProject(){
    $item_id = $this->getItem()->id;

    $db =& JFactory::getDBO();
    $query = $db->getQuery(true);
    $query->select('*');
    $query->from('#__project_part_1 AS a');
    $query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
    $query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
    $query->where('a.id = '. (int) $item_id);
    $db->setQuery($query);
    return $db->loadResult();
}

protected function loadFormData()
{
    // Check the session for previously entered form data.
    $data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());

    if (empty($data)) {
        $data = $this->getEntireProject();
    }

    return $data;
}
4

2 回答 2

5

尝试覆盖 getItem 函数。如果您在视图中调用 get('Item'),这也会很有帮助。-

public function getItem($pk = null){
    if ($item = parent::getItem($pk)) {
        $db =& JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select('*');
        $query->from('#__project_part_1 AS a');
        $query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
        $query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
        $query->where('a.id = '. (int) $item->id);
        $db->setQuery($query);          
        $item =  $db->loadAssoc();
    }   
    return $item;
}

protected function loadFormData()
{
    // Check the session for previously entered form data.
    $data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());

    if (empty($data)) {
    $data = $this->getItem();
    }

    return $data;
}
于 2012-10-17T07:11:30.813 回答
1

对于多行结果,使用 loadRowList()、loadAssocList()、loadAssocList($key)、loadObjectList()、loadObjectList('key')。$db->loadResult() 只加载一个结果。阅读更多

如果我正确理解您的问题,这应该可以解决您的问题。如果你不问。

于 2012-10-17T06:40:13.347 回答