joomla loadformdata

时间秒杀一切 提交于 2019-12-08 00:13:41

问题


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

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/12928475/joomla-loadformdata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!