我有一个项目列表页面和一个用于搜索的过滤区域。为了从过滤器表单中传递和检索变量,我使用 getUserStateFromRequest 然后我根据这些列出项目。但是当我在行或其他视图之间移动时,我返回我想重置变量以查看整个列表,但它没有。我想我应该在视图改变时重新设置它们。如何控制这个或任何其他建议?
问问题
3968 次
3 回答
2
也许您根本不想使用getUserStateFromRequest。getUserStateFromRequest 将请求变量存储到用户会话。如果您希望在离开页面时重置状态,您可以选择不在用户会话中保存变量。
在您的模型 populateState 中,类似于:
$app = JFactory::getApplication();
$search_term = $app->input->get('search_term', null, 'CMD');
$this->setState('filter.search_term', $search_term);
然后检索状态(仍在您的模型中):
$search_term = $this->getState('filter.search_term');
if($search_term != null)
$query->where('my_field = ' . $db->quote($search_term));
请注意,代码未经测试。
于 2012-08-20T14:11:06.220 回答
0
您可以像这样重置活动过滤器,然后将 resetuserstate=1 添加到查询中:
protected function populateState($ordering = null, $direction = null) {
... ... ...
parent::populateState('a.title', 'asc');
$activefilters=$this->getActiveFilters();
$jinput = JFactory::getApplication()->input;
$resetUserState=(bool) $jinput->get("resetuserstate",0, 'INT');
if ($resetUserState) {
foreach ($activefilters as $activefilter => $filterstate) {
// clearing filters
$app->setUserState($this->contect . 'filter.'. $activefilter, '');
$this->setState('filter.'.$activefilter,'');
}
}
}
注意:当您通过错误地设置过滤器来混淆用户状态时会发生奇怪的事情,登录和注销也会清除用户状态并且有时会有所帮助。
于 2014-10-05T08:45:58.533 回答
-4
我仍然无法解决我的问题:S。得到是没有用的。这些代码有什么区别
$mainframe =& JFactory::getApplication();
$filter_carryingW = $mainframe->input->get( 'filter_carryingW', '', 'int' );
$filter_carryingF = $mainframe->input->get( 'filter_carryingF', '', 'int' );
$filter_services = $mainframe->input->get( 'filter_services', '', 'int' );
$filter_country = $mainframe->input->get( 'filter_country', '', 'word' );
$filter_city = $mainframe->input->get( 'filter_city', '', 'int' );
$filter_town = $mainframe->input->get( 'filter_town', '', 'int' );
$this->setState('com_dratransport.members.filter_carryingW' , $filter_carryingW);
$this->setState('com_dratransport.members.filter_carryingF' , $filter_carryingF);
$this->setState('com_dratransport.members.filter_services' , $filter_services);
$this->setState('com_dratransport.members.filter_country' , $filter_country);
$this->setState('com_dratransport.members.filter_city' , $filter_city);
$this->setState('com_dratransport.members.filter_town' , $filter_town);
$f['filter_carryingW'] = $this->getState('com_dratransport.members.filter_carryingW');
$f['filter_carryingF'] = $this->getState('com_dratransport.members.filter_carryingF');
$f['filter_services'] = $this->getState('com_dratransport.members.filter_services');
$f['filter_country'] = $this->getState('com_dratransport.members.filter_country');
$f['filter_city'] = $this->getState('com_dratransport.members.filter_city');
$f['filter_town'] = $this->getState('com_dratransport.members.filter_town');
和
$f['filter_carryingW'] = $mainframe->input->get( 'filter_carryingW', '', 'int' );
$f['filter_carryingF'] = $mainframe->input->get( 'filter_carryingF', '', 'int' );
$f['filter_services'] = $mainframe->input->get( 'filter_services', '', 'int' );
$f['filter_country'] = $mainframe->input->get( 'filter_country', '', 'word' );
$f['filter_city'] = $mainframe->input->get( 'filter_city', '', 'int' );
$f['filter_town'] = $mainframe->input->get( 'filter_town', '', 'int' );
于 2012-08-22T19:18:22.753 回答