Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------- model --------------------------------------
- function update_counter($id_berita) {
- // return current article views
- $this->db->where('id_berita', urldecode($id_berita));
- $this->db->select('view_berita');
- $count = $this->db->get('berita')->row();
- // then increase by one
- $this->db->where('id_berita', urldecode($id_berita));
- $this->db->set('view_berita', ($count->view_berita + 1));
- $this->db->update('berita');
- }
- public function read($id_berita)
- {
- $this->db->from('berita');
- $this->db->where('id_berita', $id_berita);
- $query = $this->db->get();
- return $query->row();
- }
- ---------------------------- controler -----------------------------------
- function view($id_berita)
- {
- $data = array('berita' => $this->m_data->read($id_berita),
- 'list_berita' => $this->m_data->read_list_berita(),
- );
- $beritas = $this->m_data->read($id_berita);
- $title ['title']= $beritas->judul;
- $this->add_count($id_berita);
- $this->load->view('header',$title);
- $this->load->view('berita_view', $data);
- $this->load->view('footer');
- }
- function add_count($id_berita)
- {
- $check_visitor = $this->input->cookie(urldecode($id_berita), FALSE);
- $ip = $this->input->ip_address();
- if ($check_visitor == false) {
- $cookie = array(
- "name" => urldecode($id_berita),
- "value" => "$ip",
- "expire" => time() + 7200,
- "secure" => false
- );
- $this->input->set_cookie($cookie);
- $this->m_data->update_counter(urldecode($id_berita));
- }
- }
- -------------------------- view ----------------------------------------
- <!-- Page Content -->
- <div class="container-fluid" style="margin:100px 0px; 10px">
- <div class="margin-profile">
- <!-- Page Heading/Breadcrumbs -->
- <ol class="breadcrumb my-5">
- <li class="breadcrumb-item">
- <a href="<?php echo base_url(); ?>">Beranda</a>
- </li>
- <li class="breadcrumb-item active">
- <a href="<?php echo base_url('berita'); ?>">Berita</a>
- </li>
- <li class="breadcrumb-item active"><?php echo character_limiter($berita->judul, 60); ?></li>
- </ol>
- <div class="row">
- <!-- Sidebar Widgets Column -->
- <?php $this->load->view('sidebar_list_berita'); ?>
- <!-- Post Content Column -->
- <div class="col-lg-6">
- <h4 class="mb-3">
- <?php echo $berita->judul;?>
- </h4>
- <!-- Preview Image -->
- <img class="img-fluid rounded card-image" style="width: 100%; max-height:400px;" src="<?php echo base_url('./img/image_berita/'.$berita->img_berita) ?>" alt="">
- <hr>
- <!-- Date/Time -->
- <p style="font-size:14px !important;">Posted on <b><?php $bulan = array ( 1 =>'Januari', 'Februaru','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
- echo date("d F Y",strtotime($berita->tanggal))?></b> at <b><?php echo date("H:i A",strtotime($berita->jam))?></b></p>
- <hr>
- <div class="card-text mb-5"><?php echo $berita->isi_berita?>
- </div>
- <!-- Post Content -->
- <br>
- </div>
- <!-- Sidebar Widgets Column -->
- <?php $this->load->view('sidebar_profile_right'); ?>
- </div>
- <!-- /.row -->
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement