0
我到處搜索和搜索,但我無法找到明確的答案在這個問題上。如何實施與Kohana 2.3.x分頁搜索
我想做一個網頁搜索和分頁結果(並按標題排序)。
請參閱原型http://i55.tinypic.com/2dlrqbs.png
我想,如果一個用戶指定爲搜索條件「A」,包含「A」顯示所有名稱。我的問題是我怎樣才能把導航鏈接的字符串:?name = a。
如果我不發回搜索條件,單擊下一頁將顯示所有記錄。
我看了很多帖子關於這個問題,我還不知道怎麼辦呢
控制器代碼(草案)
function listall()
{
$limit = 2 ;
$orderby = 'u.id';
$direction = 'asc';
$name = '';
if ($_POST)
{
$name = $this->input->post('name');
}
if ($_GET)
{
$name = $this->input->post('name');
if ($this->input->get('orderby'))
list($orderby, $direction) = explode(':', $this->input->get('orderby'));
}
$view = new view('character/listall');
$db = Database::instance();
$sql = "select c.id id, c.lastactiontime, c.name character_name, k.name kingdom_name, k.image kingdom_image, from_unixtime(u.last_login, '%d-%m-%y') last_login, u.nationality
from characters c, kingdoms k, users u
where 1=1 and
c.kingdom_id = k.id and
c.user_id = u.id
" ;
if ($name != '')
$sql .= "and c.name like '%" . $name . "%'" ;
$characters = $db->query($sql);
//$characters = ORM::factory("character")->orderby($orderby, $direction)->find_all();
$this->pagination = new Pagination(array(
'base_url'=>'character/listall',
'uri_segment'=>'listall',
'style'=>'digg',
'query_string' => 'page',
'total_items'=>$characters->count(),
'items_per_page'=>$limit));
//$characters = ORM::factory("character")->orderby($orderby, $direction)->find_all($limit, $this->pagination->sql_offset);
$sql .= " order by $orderby $direction ";
$sql .= " limit $limit offset " . $this->pagination->sql_offset ;
kohana::log('debug', $sql);
$characters = $db->query($sql);
$playersinfo = Character_Model::getplayersinfo();
$view->playersinfo = $playersinfo;
$view->pagination = $this->pagination;
$view->characters = $characters;
$this->template->content = $view;
}
感謝
你的代碼應工作? AFAIR,分頁會自動添加當前查詢字符串。 – biakaveron 2010-12-16 13:41:19