2012-04-21 80 views
0

我遇到了Codeigniters分页类的一些问题。Codigniter分页 - 第一页保持大胆

问题是,即使URL中的更改,“页面1”仍然为粗体。

我的网址是这样的:

http://mypage.com/s/search+str/4/1

URI->段(3)是per_page和URI->段(4)是页码。

我已经设置了$ config ['uri_segment'] = 4;正如你在下面的代码中看到的那样。

任何人可能会看到代码有问题吗?

谢谢。

/** Load The Search model **/ 
    $this->load->model('search_model'); 

    /** Perform the search **/ 
    $this->search_model->set_search_str(decode_url($str)); 

    // prettyPrint($config['per_page']); die(); 
    $offset = $this->uri->segment(4,0); 

    /** Pagination **/ 
    $this->load->library('pagination'); 
    $config = array (
      'uri_segmet'  => 4, 
      'per_page'   => $this->uri->segment(3, 25), 
      'total_rows'  => $this->search_model->get_nums(), 
      'num_links'  => 4, 
      'base_url'   => base_url()."s/{$str}/".$this->uri->segment(3, 25), 
      'use_page_numbers' => TRUE 
     ); 

$this->pagination->initialize($config); 

$pagination_links = $this->pagination->create_links(); 

    $query = $this->search_model->search($config['per_page'], $offset); 

    $num_results = $this->search_model->get_nums(); 

    /** Set the theme data **/ 
    $data = array(
     'title'   => 'Search page', 
     'page'   => 'search', 
     's_str'   => decode_url($str), 
     'num_results'  => $num_results, 
     'results'  => $query['results'][0], 
     'pagination'  => $pagination_links 
    ); 

    /** Load the theme **/  
$this->load->theme($data); 

回答

0

尝试配置阵列中手动添加CURRENT_PAGE,并将其设置为

$data['current_page'] = $this->uri->segment(4); 

它可能会为你工作..

+0

刚刚尝试过..但它似乎不工作?我无法理解它。我试图做第四个uri段的print_r,后面跟着一个die();它确实得到正确的价值?这对我来说似乎很奇怪。它可以和我的base_url有什么关系吗? – Thomas 2012-04-22 08:19:44

+0

我有点斋戒!我尝试将'current_page'作为分页类中变量的名称'cur_page',现在它可以工作!奇怪,我必须告诉它我在哪里:)谢谢! – Thomas 2012-04-22 08:21:53

1

如果你的数据库记录,我的意思是结果是正确的页面。你只能面对与“第一个粗体链接”的问题,那么你可以设置样式(css)如下:

$ config ['first_link'] ='First_PAGE_STYLE_CLASS';

您将不得不使css如下: .Frist_PAGE_STYLE_CLASS {text-weight:normal; }

+0

的主要问题不是CSS。这是CI不会将第一个链接包裹在锚标记中的问题,因为它对页码的其余部分进行了处理。这是接缝,因为它没有检测到页面在第四个uri段中发生了变化。但我看不出我做错了什么? – Thomas 2012-04-21 17:20:30