Postingan lainnya
Pagination codeigniter 404 page not found
gan ketika saya mengklik page selanjutnya keluarnya malah 404 page not found
1.gan ini routenya:
$route['article/terpopuler'] = 'MainController/terpopuler';
2.controllernya:
public function terpopuler($offset=0){
$getdata = $this->db->get('news');
$config['total_rows'] = $getdata->num_rows();
$config['base_url'] = base_url(). 'article/terpopuler/maincontroller/terpopuler';
$config['per_page'] = 16;
$config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative;top=-25px;'>";
$config['full_tag_close'] = "</ul>";
$config['num_tag_open'] = "<li>";
$config['num_tag_close'] = "</li>";
$config['cur_tag_open'] = "<li class='disable'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tag_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tag_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tag_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tag_close'] = "</li>";
$this->pagination->initialize($config);
$data['halaman'] = $this->pagination->create_links();
$data['offset'] = $offset;
$data['contentpage'] = $this->news_model->get_terpopuler_pagination($config['per_page'],$offset);
$this->load->view('pages/article',$data);
$this->load->view('template/footer');
}
3.modelnya
public function get_terpopuler_pagination($perpage,$offset){
$query = $this->db->query("SELECT * FROM news ORDER BY visitor DESC LIMIT $perpage OFFSET $offset");
return $query->result();
}
4.viewnya
<div class="container mycontain">
<div class="row">
<?php foreach ($contentpage as $item): ?>
<div class="col mb-4">
<div class="card mycard-pemprograman">
<a href="<?php echo base_url();?>article/<?php echo $item->slug; ?>"><img class="card-img-top" src="<?php echo base_url(); ?>upload/<?php echo $item->foto; ?>" alt="Card image cap"></a>
<div class="card-body">
<a href="<?php echo base_url();?>article/<?php echo $item->slug; ?>"><h6 class="card-title"><?php echo $item->title; ?></h6></a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php echo $halaman; ?>
</div>
awalnya saya mengakses http://localhost/projekWebsite/article/terpopuler/ setelah itu saya klik page selanjutnya otomatis kan url berubah menjadi http://localhost/projekWebsite/article/terpopuler/maincontroller/terpopuler/16 dan munculnya malah 404 page not found padahal saya memiliki data sekitar >50 dari table news. apa mungkin ini kesalahan dari route atau dari url tambahan maincontroller/terpopuler/ kode di atas sudah saya coba gak ada error gan, mohon bantuanya gan analisisnya (terima kasih)
2 Jawaban:
coba jika mengunjungi "http://localhost/projekWebsite/article/terpopuler/16"
Hai @fadiljack123 sepertinya di route kamu kurang tepat. Coba dibuat seperti ini <pre> $route['article/terpopuler/(:any) '] = 'MainController/terpopuler/$1'; </pre> Tidak usah ditambahin maincontroller/terpopuler lagi