azmicolejr

untitled

Oct 16th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. Controller
  2.  
  3. <?php
  4. defined('BASEPATH') OR exit('No direct script access allowed');
  5.  
  6. class Blog extends CI_Controller {
  7.     public function kategori($id)
  8.       {
  9.             $this->load->helper('clean_helper');
  10.             $row = $this->Kategori_model->get_by_id_front($id)->result();
  11.    
  12.             if($row == FALSE)
  13.             {
  14.                 echo "<script>alert('Belum ada data.');location.replace('".base_url()."')</script>";
  15.             }
  16.             else{
  17.  
  18.             $kat = $this->uri->segment(3);
  19.    
  20.             /* menyiapkan data yang akan disertakan/ ditampilkan pada view */
  21.             $this->data['page_title']        = "$kat";
  22.    
  23.             /* memanggil function dari model yang akan digunakan */
  24.             $this->data['kategori_data']     = $this->Kategori_model->get_by_id_front($id)->result();
  25.    
  26.             /* memanggil view yang telah disiapkan dan passing data dari model ke view*/
  27.             $this->load->view('front/blog/kategori', $this->data);
  28.             }
  29.       }
  30. }
  31.  
  32. Model
  33. function get_by_id_front($id)
  34.   {
  35.     $this->db->where('slug_kategori', $id);
  36.     $this->db->order_by('id_blog','desc');
  37.     return $this->db->get('kategori');
  38.   }
  39.  
  40. View
  41. silahkan dicoba sendiri, panggil data dari controller ke view nya
Advertisement
Add Comment
Please, Sign In to add comment