我到处寻找教程,但似乎找不到一个好的教程...
- 具有分页、列标题排序和多重过滤的搜索页面(过滤器在复选框中)
问题:分页工作,排序工作,但不能让他们一起工作。添加到使过滤器使用分页和排序的结果集
我想单独使用 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)
- 用户可以过滤已排序的表(或者如果他/她没有进行任何排序,则将过滤当前表)
如果我应用所有过滤器(没有页面和排序),这就是 URL 的样子:
http://localhost/thi/search/index.html?filter[]=featured&filter[]=bankowned&filter[]=new&filter[]=owner&filter[]=broker&filter[]=bank
到目前为止它看起来很乱,但我想这就是搜索引擎网址的情况:)