【问题标题】:Adding "PAGINATION" in Zend Lucene Search result in codeigniter在 Zend Lucene 搜索结果中添加“PAGINATION”在 codeigniter
【发布时间】:2011-03-31 01:21:46
【问题描述】:

大家好,我尝试将 zend lucene 搜索系统与 codeigniter 集成。但问题是我如何在 Codeigniter 中以分页格式格式化搜索结果

下面是搜索代码:

$query//keyword to search                
$index = Zend_Search_Lucene::open(DOCROOT . 'data/index'); //opening index
$hits['post']= $index->find($query); //getting the search result

请朋友们帮帮我

【问题讨论】:

  • 这和kohana有什么关系?

标签: zend-framework codeigniter pagination zend-search-lucene


【解决方案1】:

您的控制器应如下所示:

$this->load->library('pagination');
$query_result = $index->find($query);

$offset = $this->uri->segment(3,0);
$limit = 10;

// this is the cool part, which you don't know
    $set= array();                                      
    for($i=$offset; $i< $limit + $offset; $i++)
    {
        if(array_key_exists($i, $query_result)){
            $set[]= $query_result[$i];
        }else{
            break;  
        }
    }
//end of cool part

$config['base_url'] = base_url().'search/index/';
$config['total_rows'] = count($query_result);
$config['uri_segment'] = 3;
$config['per_page'] = $limit;
$config['num_links'] =10;
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['results'] = $set;// pass the paginated resulted to the view
$this->load->view('myview',$data);

你的视图应该是这样的

<?php foreach($results as $result):?>
<?=$result->title?>
<?=$result->detail?>
<?=$result->post_date?>
<?php endforeach;?>

<?=$links?>//the pagination links

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多