我到处寻找教程,但似乎找不到好的教程......
- 具有分页、列标题排序和多重过滤的搜索页面(过滤器位于复选框中)
问题:
分页工作,排序工作,但无法让它们一起工作。添加到使过滤器与分页和排序的结果集一起使用
我想单独使用 php 和 GET 表单方法来完成这项工作(稍后引入 JavaScript,我想对此应用渐进增强)
我不知道如何使三个功能(分页、排序和过滤)一起工作......我想要实现
这是我的控制器代码
function index(){
$resultset = null;
if ($this->input->get()){
// searching
if ($this->input->get('keyword')){
$resultset = $this->hotel->searchterm($_GET['keyword']);
}
if (!$this->input->get('keyword')){
$searchkeys = array();
foreach($_GET as $key => $value){
$searchkeys[$key] = $value;
}
$resultset = $this->hotel->searchcat($searchkeys);
}
// sorting
if ($this->input->get('sortby')){
$resultset = $this->hotel->sortdefault($_GET['sortby']);
}
if ($this->input->get('keyword') && $this->input->get('sortby')){
$resultset = $this->hotel->sortdefault($_GET['sortby']);
}
}else{
$resultset = ORM::factory('hotel')->limit(15)->find_all();
}
$this->template->title = 'The Hotel Inventory :: Search';
$this->template->sidebar = new View('search-sidebar');
$this->template->featured = new View('search-details');
$this->template->featured->data = $resultset;
}
至于酒店图书馆的功能:
public function sortdefault($sort, $resultset=null){
if (!$this->session->get('sortorder')){
$_SESSION['sortorder'] = 'asc';
}else if ($this->session->get('sortorder') == 'asc'){
$_SESSION['sortorder'] = 'desc';
}else{
$_SESSION['sortorder'] = 'asc';
}
$sortorder = $this->session->get('sortorder');
$sortby = '';
switch ($sort){
case 'name' :
$sortby = 'name';
break;
case 'location':
$sortby = 'location';
break;
case 'price' :
$sortby = 'price';
}
if (is_null($resultset)){
$query = ORM::factory('hotel')->
select('id, name, location, room, price, date_added, url_path')->
limit(15)->orderby($sortby, $sortorder)->find_all();
}
return $query;
}
至于视图中的表:
<table id="tableresults" cellpadding="0" cellspacing="0" border="1" >
<thead>
<tr style="height: 20px;">
<th>Image</th>
<th><?php echo (isset($_SESSION['searchterm'])) ?
html::anchor('search/index?keyword=' . $_SESSION['searchterm'] . '&sortby=name','Hotel Name') :
html::anchor('search/index?sortby=name','Hotel Name');?></th>
<th><?php echo html::anchor('search/index?sortby=location','Location');?></th>
<th><?php echo html::anchor('search/index?sortby=price','Price');?></th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $d){
echo '<tr class="result">';
echo '<td> </td>';
echo '<td>' . html::anchor('hotel/' . $d->url_path, $d->name) . '</td>';
echo '<td>' . $d->location . '</td>';
echo '<td>USD ' . $this->util->money($d->price);
echo '<td> </td>';
echo '</tr>';
}
?>
</tbody>
- 用户搜索一个项目(单个术语搜索)或使用多个类别(多个术语搜索)
- 结果分页,以表格形式呈现,每个列标题都带有指向排序方法的链接 (sort.php?by=title)
- 用户可以过滤排序后的表(或者如果他/她没有进行任何排序,则当前表将被过滤)
如果我应用所有过滤器(尚未进行页面和排序),则网址如下所示:
http://localhost/thi/search/index.html?filter[]=featured&filter[]=bankowned&filter[]=new&filter[]=owner&filter[]=broker&filter[]=bank
现在看起来很混乱,但我想这就是搜索引擎网址的情况:)