我是俄语,很抱歉,我的英语不太好。
我的问题是关于Joomla的分页。 在我们的任务exemple.php中,我们只有一个函数display();做分页 - 很容易。
但我有一个真正的问题。在我的页面示例我有搜索表单,我需要分页搜索结果。当我开始搜索某些东西时,我看到了我的搜索表单,搜索结果,页面页脚上的分页,但是当我点击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 :(得分:0)
女贞,
你有愚蠢的问题。您原始查询生成有限数量的记录选择。
SELECT ... FROM ... WHERE ... LIMIT $limitstart, $limit
然后你使用"SELECT FOUND_ROWS();"
这将是$ limit,所以实际上你只有1页的分页。
您的查询需要像这样:
SELECT ... FROM ... WHERE ... LIMIT $limitstart, $limit
Uda4i!
答案 1 :(得分:0)
joomla分页的简单解决方案,请查看
...templates/protostar/html/pagination.php
并将其粘贴到您的
模板html文件夹...templates/mytemplate/html/pagination.php
,
根据您的喜好编辑样式