-3

我可以在 joomla 2.5 的模型中进行 2 个单独的查询吗?如果可能,您将如何做到这一点?

这是我的模型:

<?php
            defined('_JEXEC') or die();

            jimport( 'joomla.application.component.modellist' );

            class AnagraficheModelServiziassociatiaggiuntivi extends JModelList
            {
                           public function __construct($config = array())
                           {
                                           if (empty($config['filter_fields'])) 
                                           {
                                                           $config['filter_fields'] = array('id_servizi_aggiuntivi', 'id_persona', 'id_servizio', 'nome_servizio', 'cod_servizio', 'id_tipologia_socio', 'nome_servizio');
                                           }

                                           parent::__construct($config);
                           }

                           function getListQuery()
                           {              
                                           $db = JFactory::getDBO();
                                           $query = $db->getQuery(true);
                                           $query->select('id_servizi_aggiuntivi, id_persona , id_servizio , nome_servizio');
                                           $query->from('#__servizi_aggiuntivi as serviziaggiuntivi, #__elenco_servizi');
                                           $query->where('cod_servizio=id_servizio');
                                           $result1 = $db->loadObjectList();


                                           //$db->setQuery($query);

                                           $query = $db->getQuery(true);
                                           $query->select('id_tipologia_socio, id_servizio as cod_servizio, nome_servizio');
                                           $query->from('#__associazione_servizi as serviziassociati, #__elenco_servizi');
                                           $query->where('cod_servizio=id_servizio');
                                           $result1 = $db->loadObjectList();


                                           return $query;
                           }

                           protected function populateState($ordering = null, $direction = null)
                           {
                                           // Load the filter state.
                                           $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
                                           $this->setState('filter.search', $search);

                                           // List state information.
                                           parent::populateState($ordering, $direction);
                           }
            }
?>

这不起作用,但是如果我删除第二个查询,它会很好用!在我看来,问题出在函数 getListQuery() 上。在这个函数中,我想插入 2 个查询而不是 1 个查询!可能吗?

4

1 回答 1

0

最简洁的答案是不。getListQuery 应该返回一个查询。你不能让它返回两个查询。

相反,您可能希望覆盖 getItems 函数以在第一个查询运行后处理项目。您可以使用以下内容调整或添加项目:

public function getItems() {
    // load items from the parent getItems function, which will call getListQuery to handle your first query.
    //It only adds items if the first query works.
    if ($items = parent::getItems()) {
        $db = JFactory::getDbo();

        $query = $db->getQuery(true);
        $query->select('id_tipologia_socio, id_servizio as cod_servizio, nome_servizio');
        $query->from('#__associazione_servizi as serviziassociati, #__elenco_servizi');
        $query->where('cod_servizio=id_servizio');
        $result1 = $db->setQuery($query)->loadObjectList();

        // this is a simple way to merge the objects. You could do other processing (loops, etc) to meld the information together
        $items = (object) array_merge((array) $items, (array) $restult1);
    }
    return $items;
}
于 2013-07-16T16:54:08.180 回答