2014-10-03 65 views
0

嗨,这可能是很明显的,但我是新来的分页,我认为CI的文档是真的垃圾,我期望得到的是一个链接列表和时我点击每一个应该显示每页3我的李项目,它显示链接列表和链接的工作,但它不显示每页的一定数量的结果,有没有人可以帮助我呢?CodeIgniter:分页显示链接,但不显示每页的确定结果

我的控制器部分:

public function clist() 
    { 
     //load the model that gets a list of clients 
     $this->load->model('list_model'); 
     //call the function that lists clients and store the return data in a variable 
     $fields = $this->list_model->listcliname(); 
     //create an array 
     $data = array(); 
     //assign the data to a key in the array 
     $data['fields'] = $fields; 
     //pass the array to view for handling and load the view. 

     $this->load->library('pagination'); 

    $config['base_url'] = site_url('clientlist/clist'); 
    $config['total_rows'] = 500; 
    $config['per_page'] = 3; 
    $this->pagination->initialize($config); 
    echo $this->pagination->create_links(); 

    $this->load->view('clientlist', $data); 

笔者认为:

<html> 
<head> 
<title> client list </title> 
<link rel="stylesheet" type="text/css" href="/css/clientlist.css"> 
<!-- add script to add jquery and add a function that performs a confirm on the event of a click on the delete link. --> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $('.confirmation').on('click', function() { 
     return confirm('Are you sure?'); 
    }); 
    }); 
</script> 
</head> 
    <body> 
     <div id="container"> 
      <?php 
      foreach($fields as $field) { 
       ?> 
       <ul> 
       <li> 
       <?php echo $field['name']; ?> 
       </li> 
       <li> 
       <?php echo $field['contact']; ?> 
       </li> 
       <li> 
       <form action="clistedit" method="post"> 
       <input type="hidden" name="sub" value="1" /> 
       <input type="hidden" name="UID" value="<?php echo $field['UID']?>"> 
       <button type="submit">edit</button> 
       </form> 
       </li> 
       <li> 
       <a href="/clientlist/delete/<?php echo $field['UID']; ?>/" class="confirmation">delete</a> 
       <a href="/clientlist/salelead/<?php echo $field['UID']; ?>/">view lead</a> 
       </li> 
       </ul> 
       <?php 
      } 

      ?> 
     </div> 

编辑:我必须某处配置哪些数据是分页或不链接到功能做到这一点?

+0

echo'

'; print_r($fields); echo '
';好像 ? – 2014-10-03 07:10:22

+0

它打印出我在第1页 – seanyt123 2014-10-03 07:13:47

+0

和2等所有的数组,就像链接链接到完全相同的东西,只是没有限制。 – seanyt123 2014-10-03 07:14:28

回答

0

你没有指定你的uri的哪一部分将包含你的page_number,也就是uri_segment配置的分页。

通常情况下,页码将在您的URI的末尾找到clientlist/clist

控制器代码将为:

$config['base_url'] = site_url('clientlist/clist'); 
$config['total_rows'] = 500; 
$config['per_page'] = 3; 
//Appends the page number to the url 
$config['uri_segment'] = 3; 
$this->pagination->initialize($config); 
$data['pagination'] = $this->pagination->create_links(); 

而在你看来,你将不得不呼应$pagination到接收分页链接。

+0

对不起,但这个答案并不真正有帮助,uri_segment并不是必须的配置,它有一个默认值,也是我的问题不是看到分页链接,我可以看到它们很好,因为我可以使用echo $这 - > pagination-> create_links();在我的控制器中像我一样看到它们,问题是结果不受限制,每个页面显示所有结果。 – seanyt123 2014-10-03 07:52:07