codeigniter分页不是wotking

时间:2017-08-29 10:08:21

标签: php codeigniter pagination

我花了这么多时间来解决它,但问题是一样的,我需要在我的应用程序中加入分页,我已经加载了分页库,我无法理解是什么问题,下面是我的代码。

控制器

public function index($offset=0)
{

    $cnt=count($this->model->getDatamodel('item_cat_master'));
    $this->load->library('pagination');
    $config['base_url'] = base_url().'item/itemcat';
    $config['total_rows'] = $cnt;
    $config['per_page'] = 4; 
    $this->pagination->initialize($config); 
    $data['view'] = $this->model->get_my_data('item_cat_master', $config['per_page'], $offset);
    $this->load->view('header');
    $this->load->view('menu');
    $this->load->view('item/item_cat', $data);
    $this->load->view('footer');


}

模型

public function getDatamodel($table)
{
$query=$this->db->get($table);
return $query->result_array();
}

Public function get_my_data($table, $limit, $offset) 
{
$query = $this->db->get($table, $limit, $offset);
return $query->result_array();
}

查看

<div class="row">
                    <div class="col-md-12">
                        <!-- start:dynamic data table -->
                        <div class="adv-table">
                            <table  class="display table table-striped" id="example">
                                <thead>
                                    <tr>
                                        <th><input id="checkAll" type="checkbox"></th>
                                        <th>Category Name</th>
                                        <th>Category Description</th>
                                        <th>Modidied On</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($view as $key) { ?>                 
                                    <tr>
                                        <td><input type="checkbox" name="ck[]" value="<?php echo $key["cat_id"]; ?>"></td>
                                        <td><?php echo $key["ic_name"]; ?></td>
                                        <td><?php echo $key["ic_desc"]; ?></td>
                                        <td><?php $mo = $key["modifiedon"]; echo date("d-M-Y , H:i:s", strtotime($mo)); ?></td>
                                        <td>
                                        <?php
                                        $this->load->model('alldata','model'); 
                                        $encrypted_id = $this->model->encryptdata($key['cat_id']); 
                                        ?>
                                        <a href="<?php echo base_url(); ?>item/itemcat/upditemcat/<?php echo $encrypted_id; ?>" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="left" title="" data-original-title="Update"><i class="fa fa-pencil"></i></a>    
                                        <!-- <a href="#" class="btn-success btn-xs" title="view"><i class="fa fa-eye" aria-hidden="true"></i> </a> --></td>
                                    </tr>
                                <?php } ?>    


                                </tbody>
                            </table>
                        </div>
                        <!-- end:dynamic data table -->
                    </div>
                </div>
                <?php
                   echo $this->pagination->create_links();
                ?>

我的代码中有什么问题?任何人都可以指导我正确的方向吗?

enter image description here

在config.php中

$config['base_url'] = 'http://localhost/riims';

htaccess的

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /riims/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<ifmodule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</ifmodule>

1 个答案:

答案 0 :(得分:2)

您的主要方法是index,默认情况下会调用。但是当您使用分页时,您必须在网址中添加index,或者您必须相应地配置route。在分页网址中添加index,然后尝试

public function index($offset=0)
{

    $cnt=count($this->model->getDatamodel('item_cat_master'));
    $this->load->library('pagination');
    $config['base_url'] = base_url().'item/itemcat/index'; //add index at end
    $config['total_rows'] = $cnt;
    $config['per_page'] = 4; 
    $this->pagination->initialize($config); 
    $data['view'] = $this->model->get_my_data('item_cat_master', $config['per_page'], $offset);
    $this->load->view('header');
    $this->load->view('menu');
    $this->load->view('item/item_cat', $data);
    $this->load->view('footer');


}