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

これは機能しませんが、2 番目のクエリを削除するとうまく機能します。私の意見では、問題は関数 getListQuery() にあります。この関数では、1 つのクエリではなく 2 つのクエリを挿入します。出来ますか?

4

1 に答える 1

0

短い答えはノーです。getListQuery はクエリを返す必要があります。2 つのクエリを返すことはできません。

代わりに、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 に答える