Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Blog extends CI_Controller {
- public function kategori($id)
- {
- $this->load->helper('clean_helper');
- $row = $this->Kategori_model->get_by_id_front($id)->result();
- if($row == FALSE)
- {
- echo "<script>alert('Belum ada data.');location.replace('".base_url()."')</script>";
- }
- else{
- $kat = $this->uri->segment(3);
- /* menyiapkan data yang akan disertakan/ ditampilkan pada view */
- $this->data['page_title'] = "$kat";
- /* memanggil function dari model yang akan digunakan */
- $this->data['kategori_data'] = $this->Kategori_model->get_by_id_front($id)->result();
- /* memanggil view yang telah disiapkan dan passing data dari model ke view*/
- $this->load->view('front/blog/kategori', $this->data);
- }
- }
- }
- Model
- function get_by_id_front($id)
- {
- $this->db->where('slug_kategori', $id);
- $this->db->order_by('id_blog','desc');
- return $this->db->get('kategori');
- }
- View
- silahkan dicoba sendiri, panggil data dari controller ke view nya
Advertisement
Add Comment
Please, Sign In to add comment