【问题标题】:Codeigniter Pagination URL issueCodeigniter 分页 URL 问题
【发布时间】:2011-12-28 17:09:05
【问题描述】:

我刚刚在我的网站www.reviewongadgets.com实现了分页

当我点击主页时,它分为两个页面,这是正确的,但是当我点击下一个链接时,它显示的 URL 为

http://www.reviewongadgets.com/home/10 

这也是正确的,但是当我回到上一页码时,它会将 URL 显示为

http://www.reviewongadgets.com/home/home/

那么你能帮忙解决这个问题吗?下面是控制器 sn-p 其中$urlhttp://www.reviewongadgets.com/home

$config['base_url'] = $url;
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10; 
$base_url = site_url('/');
$config['uri_segment'] = '2';
//$config['page_query_string'] = TRUE;
$this->pagination->initialize($config); 

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    这应该对你有用(著名的遗言)

    //Add this to your routes
    $route['home/(:num)'] = 'home/index/$1';
    
    
    public function index($offset=0){
    
    $limit = $this->config->item('pagination_per_page'); // default 10
    
    //find data based on limits and offset
    $query = //you query LIMIT = $limit OFFSET = $offset
    
    $count = //count the number of rows returned by $query
    
    //init pagination attributes
    $config = array(
            'base_url' => site_url('home'),
            'total_rows' => $count,
            'per_page' => $limit,
            'uri_segment' => 2
        );
    $this->pagination->initialize($config); 
    
    //load the view and pagination data
    $this->load->view('some_view', array(
            'pagination'  =>  $this->pagination->create_links(),
            'data'  => //data return from $query as object or array
    ));
    }
    

    【讨论】:

      【解决方案2】:

      问题可能在于您如何定义 base_url,因为您给了它一个变量,但您没有告诉它在哪里以及如何为其分配值。尝试:

      $config['base_url'] = site_url('home');
      $config['total_rows'] = $this->MiscellaneousModel->countEntries();
      $config['per_page'] = 10; 
      $config['uri_segment'] = '2';
      

      由于您使用的是索引方法,也许指定它可以解决问题(我曾经遇到过类似的问题并且确实有效)

      $config['base_url'] = site_url('home/index');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-04
        • 1970-01-01
        • 2015-04-27
        • 2014-01-10
        • 2017-01-16
        • 2014-09-21
        • 2019-05-08
        相关资源
        最近更新 更多