joomla 组件搜索

Posted

技术标签:

【中文标题】joomla 组件搜索【英文标题】:joomla component searching 【发布时间】:2014-11-14 14:22:37 【问题描述】:

请帮助我的模型能够从数据库中获取数据,但如果我想要一个特定的结果集它会一直给我相同的数据,那么我无法过滤

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

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();
    

【问题讨论】:

没有表格和表格的详细信息,很难判断出什么问题。另外第二个if 条件看起来也不正确。应该是$destto = $this->getState('filter.to');if (!empty($destto)) 【参考方案1】:

您还应该在模型中为 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') 的设置是否正确。

【讨论】:

以上是关于joomla 组件搜索的主要内容,如果未能解决你的问题,请参考以下文章

Joomla 组件 - 列表视图管理页面 - 搜索不起作用

如何通过自定义组件文件搜索Joomla前端com_search组件的mysql表?

将搜索 DIV 添加到 Joomla 3.0 组件视图时 CSS 丢失

Joomla 3.0 组件参数存储在哪里?

在 joomla 组件中传递获取变量

Joomla 上的智能搜索插件:没有结果