2014-09-19 3 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

답변

0

에 도움을 주셔서 감사합니다 당신은 또한 당신의 filter.to 모델 및 filter.from에 populateState()를 오버라이드 (override) :

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