【问题标题】:codeigniter pagination not wotkingcodeigniter分页不起作用
【发布时间】:2017-08-29 10:08:20
【问题描述】:

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

控制器

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();
                ?>

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

在 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>

【问题讨论】:

  • 那么,有什么问题?分页不显示或分页不工作?
  • 链接显示但页面不显示,404页面未找到
  • 用路线更新您的问题
  • 所以,只有 URL 问题。检查一次,分页链接中是否存在所需的 URL。可能是,没有提供正确的 URL。
  • 所以item/itemcatitemcat 函数在itemcontroller 中可用?

标签: php codeigniter pagination


【解决方案1】:

您的主要方法是index,默认情况下会调用它。但是当你使用分页时,你必须在 url 中添加index,或者你必须相应地配置route。在分页url中添加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');


}

【讨论】:

    猜你喜欢
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-30
    相关资源
    最近更新 更多