因为分页是使用getUserStateFromRequest方法来获取limit和limitstart变量,所以我遇到了一个问题,当我从一个组件导航到另一个组件时,我显示没有找到项目的消息.
为了澄清,我有一个产品组件,其中列出了3页的产品.然后我有一个分支组件,有2页的分支信息.因此,如果我导航到产品列表中的第三页,然后转到分支组件,则不会显示任何内容.
有谁知道如何阻止这种情况发生?有没有办法清除会话数据?
我最终做的是这样的,在libraries/joomla/application/application.php文件的第624行中我添加了以下几行
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );;
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
Run Code Online (Sandbox Code Playgroud)
所以整个函数读取这个,
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
{
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
$cur_state = $this->getUserState($key, $default);
$new_state = JRequest::getVar($request, null, 'default', $type);
// Save the new value only if it was set in this request.
if ($new_state !== null)
{
$this->setUserState($key, $new_state);
}
else
{
$new_state = $cur_state;
}
return $new_state;
}
Run Code Online (Sandbox Code Playgroud)
目前这似乎运行良好。但请在实际站点上实施之前进行测试