joomla loadformdata

2019-05-18 21:08发布

how to show data from 3 tables in one view, because using JTable i can show data only bind to that JTable, please help me with this one.

my code so far(not working) in models:

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

2条回答
唯我独甜
2楼-- · 2019-05-18 21:47

try to overwrite getItem function.This will also be helpful if you are calling get('Item') in view. -

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;
}
查看更多
神经病院院长
3楼-- · 2019-05-18 21:54

For Multi-Row Results use loadRowList(), loadAssocList(), loadAssocList($key), loadObjectList(), loadObjectList('key'). $db->loadResult() only load one result. Read more.

If I understand your question right this should fix your problem. If you not please ask.

查看更多
登录 后发表回答