0
我試圖使用Codeigniter內置分頁庫進行分頁,但沒有從視圖中的數據庫獲取結果。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';
謝謝
你的路由的變化順序。即'$ route ['jobs /(:num)/(:any)'] ='jobs/preview/$ 1'; $ route ['jobs /(:any)'] ='jobs';' – Tpojka