2010-08-05 6 views
1

내가, 미안, 러시아어 해요 내가줌라 매김 문제

내 질문의 Joomla 매김에 관한 것입니다) 영어로 너무 좋은 아니에요. 우리의 작업에서 exemple.php는 하나의 function display()입니다. 페이지 매기기를 쉽게 만들 수 있습니다.

하지만 실제 문제가 있습니다. 내 페이지 exemple에 나는 검색 양식을 가지고 있고 나는 검색 결과를 페이지 매김 (paginate)해야한다. 나가 무언가를 찾는 것을 시작할 때 좋은 나의 모양, 페이지의 보행자에 좋은 페이지 매김을보고 그러나 나가 어떤 결과도없이 열리는 2,3 ..... 페이지를 클릭 할 때 - 단지 수색 모양. 내 작업에 exemple.php 나는 아래의 4 가지 기능이 있습니다. 모든 페이지 매김 페이지 주변의 페이지 매김 작업을 도와주세요.

감사합니다.

class SearchTask extends Controller 

{

var $_plugins  = null; 



function SearchTask() 
{ 
    $this->toolbar = MY_TOOLBAR_SEARCH; 
    $this->_plugins = new MYPlugins(); 
} 

function display() 
{ 
    global $Itemid,$MY_LANG, $_MY_CONFIG, $pagination, $total, $limitstart, $limit; 

    $mainframe =& JFactory::getApplication(); 
    $my   =& JFactory::getUser(); 
    myAddPageTitle(JText::_('SEARCH BLOG ENTRY TITLE')); 


    $template = new Template(time() . $my->usertype . $_MY_CONFIG->get('template')); 

    $blogger  = JRequest::getVar('blogger','','POST','string'); 
    $keyword  = JRequest::getVar('keyword','','POST','string'); 
    $catid   = JRequest::getVar('catid','','POST','int'); 
    $from   = JRequest::getVar('from','','POST'); 
    $to   = JRequest::getVar('to','','POST'); 
    $agefrom   = JRequest::getVar('agefrom','','POST','int'); 
    $ageto   = JRequest::getVar('ageto','','POST','int'); 
    $onan   = JRequest::getVar('onan','','POST','int'); 

    $limitstart = JRequest::getVar('limitstart', '0', 'GET'); 
    $limit  = "2"; 
    // Display form for user 
    $searchURL = JRoute::_('index.php?option=com_exemple&task=search&Itemid=' . myGetItemId()); 

    $template->set('searchURL', $searchURL); 
    $template->set('Itemid', myGetItemId()); 
    $results = false; 
    if((!empty($blogger) && isset($blogger)) || (!empty($keyword) && isset($keyword)) || (!empty($catid) && isset($catid)) || (!empty($from) && isset($from)) || (!empty($to) && isset($to)) || (!empty($agefrom) && isset($agefrom)) || (!empty($ageto) && isset($ageto)) || (!empty($onan) && isset($onan))) 
    { 
     // Post action, perform search 
     $results = $this->_search(array('blogger' => $blogger, 'keyword' => $keyword, 'catid' => $catid, 'from' => $from, 'to' => $to, 'agefrom' => $agefrom, 'ageto' => $ageto, 'onan' => $onan)); 
    } 

    if($results>0) 
    { if ((!empty($blogger) && isset($blogger)) && (!empty($keyword) && isset($keyword)) && (!empty($catid) && isset($catid)) && (!empty($from) && isset($from)) && (!empty($to) && isset($to)) && (!empty($agefrom) && isset($agefrom)) && (!empty($ageto) && isset($ageto)) && (!empty($onan) && isset($onan))) 
     {$sorry = "<div style='padding-top:20px;'>No result for <b>$keyword</b> and <b>$blogger</b></div>";} 
     else {$sorry = "<div style='padding-top:20px;'>No result for <b>$blogger</b><b>$keyword</b></div>";} 
    } 
    else{$sorry = "";} 

    echo $limitstart; 
    echo $limit; 
    $template->set('blogger', $blogger); 
    $template->set('keyword', $keyword); 
    $template->set('catid', $catid); 
    $template->set('from', $from); 
    $template->set('to', $to); 
    $template->set('agefrom', $agefrom); 
    $template->set('ageto', $ageto); 
    $template->set('onan', $onan); 
    $template->set('results', $results); 
    $template->set('total', $total); 
    $template->set('sorry', $sorry); 
    $template->set('pagination', $pagination); 
    $content = $template->fetch($this->_getTemplateName('search')); 

    return $content; 
} 

/** 
* _search 
* params: $filter (assoc array) 
**/    
function _search($filter) 
{ 

    JRequest::checkToken() or jexit('Invalid Token'); 
    global $_MY_CONFIG, $keyword, $pagination, $total, $limitstart, $limit; 

    $db   =& JFactory::getDBO(); 
    $limitstart = JRequest::getVar('limitstart', '0', 'GET'); 
    $limit  = "2"; 
    $blogger = isset($filter['blogger']) ? $db->getEscaped($filter['blogger']) : ''; 
    $keyword = isset($filter['keyword']) ? $db->getEscaped($filter['keyword']) : ''; 
    $catid  = isset($filter['catid']) ? $db->getEscaped($filter['catid']) : ''; 
    $from  = isset($filter['from']) ? $db->getEscaped($filter['from']) : ''; 
    $to  = isset($filter['to']) ? $db->getEscaped($filter['to']) : ''; 
    $agefrom  = isset($filter['agefrom']) ? $db->getEscaped($filter['agefrom']) : ''; 
    $ageto  = isset($filter['ageto']) ? $db->getEscaped($filter['ageto']) : ''; 
    $onan  = isset($filter['onan']) ? $db->getEscaped($filter['onan']) : ''; 

    if (!empty($filter['from']) && !preg_match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$^",$from)) 
    { 
     JError::raiseWarning(100, 'Some error'); 
     return; 
    } 
    if (!empty($filter['to']) && !preg_match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$^",$to)) 
    { 
     JError::raiseWarning(100, 'Some error'); 
     return; 
    } 

    $query = (!empty($filter['blogger']) || !empty($filter['keyword']) || !empty($filter['catid']) || !empty($filter['from']) || !empty($filter['to']) || !empty($filter['agefrom']) || !empty($filter['ageto']) || !empty($filter['onan'])) ? 'SELECT SQL_CALC_FOUND_ROWS id,title,introtext,created_by,catid,created,vozvras,anonym FROM #__content WHERE ' : ''; 


    if(!empty($keyword)) 
    { 
    $query  .= " (`title` LIKE '%{$keyword}%' " 
         . "OR `introtext` LIKE '%{$keyword}%')"; 
    } 


    if(!empty($blogger)) 
    { 
     if(!empty($keyword)) 
     { 
      $query .= " AND `created_by`='" . myGetAuthorId($blogger) ."'"; 
     } 
     else 
     { 
      $query .= " `created_by`='" . myGetAuthorId($blogger) ."'"; 
     } 
    } 


    if(!empty($catid) && is_numeric($catid)) 
    { 
     if(!empty($blogger) || !empty($keyword)) 
     { 
     $query .= ' AND `catid`=' .(int) $catid . ' '; 
     } 
     else 
     { 
      $query .= ' `catid`=' .(int) $catid . ' '; 
     } 
    } 


    if(!empty($from)) 
    { 
     $datefrom =& JFactory::getDate($from); 
     if(!empty($blogger) || !empty($keyword) || !empty($catid)) 
     { 
     $query .= " AND `created`>='{$datefrom->toMySQL()}'"; 
     } 
     else 
     { 
      $query .= " `created`>='{$datefrom->toMySQL()}'"; 
     } 
    } 

    if(!empty($to)) 
    { 

     $to .=' 23:59:59'; 
     $dateto =& JFactory::getDate($to); 
     if(!empty($blogger) || !empty($keyword) || !empty($catid) || !empty($from)) 
     { 
     $query .= " AND `created`<='{$dateto->toMySQL()}'"; 
     } 
     else 
     { 
      $query .= " `created`<='{$dateto->toMySQL()}'"; 
     } 
    } 


    if(!empty($agefrom)) 
    { 
     if(!empty($blogger) || !empty($keyword) || !empty($catid) || !empty($from) || !empty($to)) 
     { 
     $query .= ' AND `vozvras`>=' .(int) $agefrom . ' '; 
     } 
     else 
     { 
     $query .= ' `vozvras`>=' .(int) $agefrom . ' '; 
     } 
    } 



    if(!empty($ageto)) 
    { 
     if(!empty($blogger) || !empty($keyword) || !empty($catid) || !empty($from) || !empty($to) || !empty($agefrom)) 
     { 
     $query .= ' AND `vozvras`<=' .(int) $ageto . ' '; 
     } 
     else 
     { 
     $query .= ' `vozvras`<=' .(int) $ageto . ' '; 
     } 
    } 


    if(!empty($onan)) 
    { 
     if(!empty($blogger) || !empty($keyword) || !empty($catid) || !empty($from) || !empty($to) || !empty($agefrom) || !empty($ageto)) 
     { 
     $query .= ' AND `anonym`=' .(int) $onan . ' '; 
     } 
     else 
     { 
     $query .= ' `anonym`=' .(int) $onan . ' '; 
     } 
    } 
    $sections = $_MY_CONFIG->get('managedSections'); 
    $query .= " AND `sectionid` IN ({$sections}) AND `state`='1' ORDER BY `created` DESC LIMIT $limitstart, $limit"; 
    $db->setQuery($query); 
    $results = $db->loadObjectList(); 
    $db->setQuery("SELECT FOUND_ROWS();"); 
     $total  = $db->loadResult(); 
     jimport('joomla.html.pagination'); 
     $pagination = new JPagination($total , $limitstart , $limit); 
     $pagination = $pagination->getPagesLinks(); 

    $this->_format($results); 


    return $results; 
} 

function _format(&$rows) 
{ 
    global $_MY_CONFIG, $keyword; 

    // Load Plugins 
    $this->_plugins->load(); 

    // Format results 
    for($i =0; $i < count($rows); $i++){ 
     $row =& $rows[$i]; 


     $row->text = SearchHelper::prepareSearchContent($row->introtext, 200, $keyword); 
     $row->text = preg_replace("/$keyword/i", "<span class='highlight'>$keyword</span>", $row->text); 
     $row->user  = myGetAuthorName($row->created_by, $_MY_CONFIG->get('useFullName')); 
     $row->user  = $row->user; 
     $row->link  = myGetPermalinkURL($row->id); 
     $row->userlink = JRoute::_('index.php?option=example&blogger=' . myGetAuthorName($row->created_by)); 
     $row->jcategory  = '<a href="' . JRoute::_('index.php?option=example&task=tag&category=' . $row->catid) . '"><b id="bold">' . myGetJoomlaCategoryName($row->catid) . '</b></a>'; 
     $avatar = 'My' . ucfirst($_MY_CONFIG->get('avatar')) . 'Avatar'; 
     $avatar = new $avatar($row->created_by); 

     $row->avatar = $avatar->get(); 

     $date   =& JFactory::getDate($row->created); 
     $date->setOffSet($_MY_CONFIG->get('dateFormat')); 
     $row->date  = $date->toFormat(); 
    } 
} 

}

답변

0

쥐똥 나무 속의 식물,

당신은 바보 문제가 있습니다. 당신은 원래 쿼리 생성 제한된 수의 레코드를 선택합니다.

SELECT ... FROM ... WHERE ... LIMIT $limitstart, $limit 

그런 다음 당신은 실제로 당신이 매김 만 1 페이지가 있으므로, $ 제한 될 것이다 "SELECT FOUND_ROWS();"을 사용하고 있습니다.

당신의 쿼리는 다음과 같이해야 : FROM ... WHERE

  1. SELECT ... FROM ... WHERE ... LIMIT $limitstart, $limit
  2. `SELECT COUNT (*)를 ...

Uda4i을!

0

의 joomla 매김에 대한 간단한 솔루션, 원하는대로, 스타일

편집을

...templates/protostar/html/pagination.php에서의보고 당신의

템플릿 HTML 폴더 ...templates/mytemplate/html/pagination.php에 붙여 복사