Codeigniter分页不显示结果

时间:2017-05-25 16:27:46

标签: php codeigniter pagination

我正在尝试使用Codeigniter内置分页库进行分页,但是没有从数据库中获取结果。

我不知道我哪里错了。

如果有人可以帮助我,我会在下面发布我的代码。谢谢

模特

 public function showAll($limit, $offset){

        $this->db->limit($limit);
        $this->db->offset($offset);
        return $this->db->get('jobs')->result();
    }

    public function countAll($value='')
    {
        return $this->db->get('jobs')->num_rows();
    }

控制器

$total = $this->JobsM->countAll();
            $limit = 3;
            $offset = $page;


            $config['base_url'] = base_url('jobs/');
            $config['total_rows'] = $total;
            $config['per_page'] = $limit;
            $config['uri_segment'] = 2;
            $config['use_page_numbers'] = TRUE;

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


            $data['myData'] = $this->MusiciansM->myProfile();
            $data['jobList'] = $this->JobsM->showAll($offset, $limit);
            $data['pagination'] = $this->pagination->create_links();


            $this->load->view('user/header', $data);
            $this->load->view('public/job-list', $data);
            $this->load->view('public/footer');

查看

<div class="row">
                    <?php if(isset($jobList)):?>
                        <?php foreach($jobList as $job): ?>
                            <div class="col-md-12 job-item">
                                <a href="<?php echo base_url().'jobs/'.$job->id.'/'.url_title($job->title);?>" class="thumbnail">
                                <h3 class="job-title"><?php echo word_limiter($job->title, 5);?> <small> <?php echo $job->musicianType;?> </small></h3>
                                    <p class="description"><?php echo character_limiter($job->description, 200);?></p>
                                    <?php $date = date('d-m-Y', strtotime($job->date));?>


                                    <p><small class="dateandplace"> <?php echo $date;?> </small></p>
                                </a>
                            </div>
                        <?php endforeach;?>
                    <?php endif;?>
                </div>
                <!-- Pagination -->
                <div class="row pagination">
                    <div class="col-md-12">
                        <?php print_r($pagination) ;?>
                    </div>
                </div>
                <!--/ Pagination -->

路线

$route['jobs/(:any)'] = 'jobs';
$route['jobs/(:num)/(:any)'] = 'jobs/preview/$1';

谢谢

1 个答案:

答案 0 :(得分:0)

$this->pagination->create_links();以字符串形式返回分页。 在print_r中打印字符串是错误的。

<!-- Pagination -->
 <div class="row pagination">
   <div class="col-md-12">
      <?php print_r($pagination) ;?>
   </div>
 </div>
<!--/ Pagination -->

正确的形式是:

<!-- Pagination -->
 <div class="row pagination">
   <div class="col-md-12">
      <?php echo $pagination; ?>
   </div>
 </div>
<!--/ Pagination -->