【发布时间】:2015-06-16 04:33:41
【问题描述】:
在我的 joomla 3.x 组件中,我有列表视图管理页面,我在其中添加了一些搜索工具:
<div class="filter-search btn-group pull-left">
<label for="filter_search" class="element-invisible"><?php echo JText::_('JSEARCH_FILTER');?></label>
<input type="text" name="filter_search" id="filter_search" placeholder="<?php echo JText::_('JSEARCH_FILTER'); ?>" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo JText::_('JSEARCH_FILTER'); ?>" />
</div>
<div class="btn-group pull-left">
<button class="btn hasTooltip" type="submit" title="<?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?>"><i class="icon-search"></i></button>
<button class="btn hasTooltip" id="clear-search-button" type="button" title="<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>"><i class="icon-remove"></i></button>
</div>
但显然它不起作用。我应该如何以及在哪里添加对该搜索的支持?我想我应该在模型中添加一些动作?
我希望搜索仅在我的数据表的某些列(7 列中的 2 列)上起作用。
更新:
在我的populateState 方法中的模型文件中,我有:
// Load the filter state.
$search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
在getListQuery 方法中:
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('a.email = ' . $search );
} else {
$search = $db->Quote('%' . $db->escape($search, true) . '%');
}
}
更新 2:
好的,我设法让搜索为我工作。我不知道为什么一些默认的 joomla 语法破坏了我的搜索。
实际上,在我的模型文件中注释掉 getListQuery 中的一些元素并添加适当的 where 子句就可以了:
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
//if (stripos($search, 'email:') === 0) {
$query->where('a.email LIKE "%' . $search .'%" OR a.imie LIKE "%'.$search.'%"' );
// } else {
// $search = $db->Quote('%' . $db->escape($search, true) . '%');
//
// }
}
所以我坚持我的赏金来解释为什么我必须从getListQuery评论这些部分
【问题讨论】:
标签: joomla components