【问题标题】:joomla component searchingjoomla 组件搜索
【发布时间】: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)) {

标签: php joomla components


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-14
    • 2011-03-13
    • 2012-06-20
    • 2011-06-26
    • 2015-11-19
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多