2014-09-19 85 views
2

请帮助我的模型能够从数据库中获取数据,但我不能够过滤,如果我想要一个特定的结果集,它不断给我同样的数据的Joomla组件搜索

这是我的代码。感谢您的帮助提前

public function __construct($config = array()) { 
       $config['filter_fields']=array(
       'b.start', 
       'd.`title` ', 
       'e.`title`'); 
       parent::__construct($config); 
     } 

    function getListQuery() 
    { 
    $db = JFactory::getDBO(); 
     $query = $db->getQuery(true); 
    $query->select('a.firstname, a.lastname, b.start, c.flightnumber, d.`title` TO_NAME, e.`title` FROM_NAME, c.id'); 
    $query->from(' #__bookpro_passenger as a'); 
    $query->JOIN('INNER', '#__bookpro_orderinfo as b ON a.order_id = b.order_id'); 
    $query-> JOIN('INNER','#__bookpro_flight as c ON b.obj_id = c.id'); 
    $query-> JOIN('INNER','#__bookpro_dest as d ON c.desfrom = d.id'); 
    $query-> JOIN('INNER',' #__bookpro_dest as e ON c.desto = e.id'); 



     $destfrom = $this->getState('filter.from'); 
       if (!empty($destfrom)) { 
       $destfrom = $db->Quote('%'.$db->escape($destfrom, true).'%'); 
       $query->where('(e.`title` LIKE '.$destfrom.')'); 
    } 


     $destfrom = $this->getState('filter.to'); 
       if (!empty($destfrom)) { 
       $destto = $db->Quote('%'.$db->escape($destto, true).'%'); 
       $query->where('(d.`title` LIKE '.$destto.')'); 
    } 
    return $query; 
    } 

    function populateState() 
     { 

       $app = JFactory::getApplication(); 


       $destfrom = $app->getUserStateFromRequest($this->context.'.filter.from', 'filter_from'); 

       $this->setState('filter.from', $destfrom); 
       $destto = $app->getUserStateFromRequest($this->context.'.filter.to', 'filter_to'); 

       $this->setState('filter.to', $destto); 


       parent::populateState(); 
    } 
} 
+0

没有表格和表格细节,很难说出什么问题。此外,第二个'if'条件也看起来不正确。它应该是'$ destto = $ this-> getState('filter.to'); if(!empty($ destto)){' – Irfan 2014-09-20 12:21:56

回答

0

你也应该在你的型号为filter.tofilter.from覆盖populateState():

protected function populateState($ordering = null, $direction = null) { 
    $app = JFactory::getApplication('administrator'); 
    $filter.to = $app->input->get('filter.to'); 
    $this->setState('filter.to', $rfilter.to); 
    // ... 
    // your default sorting 
    parent::populateState('a.firstname', 'asc'); 
} 

无论哪种方式,检查$this->getState('filter.from')是正确设置。

-1

非常感谢它覆盖了populateState()

+0

这不是一个答案,你可以在用户的回答下添加评论。 – emmanuel 2014-10-08 17:11:29