Assalam, berikut saya bimbing untuk menambahkannya,..
pertama copas table "Komentar" pada CMS Swarakalibata,..
Selanjutnya Copas beberapa model dari Model_berita.php dari swarakalibata ke Model_berita.php di UIR yaitu :
public function insert($table,$data){
return $this->db->insert($table, $data);
}
public function view_where($table,$data){
$this->db->where($data);
return $this->db->get($table);
}
public function view_where_ordering_limit($table,$data,$order,$ordering,$baris,$dari){
$this->db->where($data);
$this->db->order_by($order,$ordering);
$this->db->limit($dari, $baris);
return $this->db->get($table);
}
Selanjutnya kita Copas funvtion kirimkan_komentar dari Controller "Berita.php" Swarakalibata ke UIR :
function kirim_komentar(){
if (isset($_POST['submit'])){
$cek = $this->db->query("SELECT * FROM berita where id_berita='".$this->input->post('a')."'");
$row = $cek->row_array();
if ($cek->num_rows()<=0){
redirect('main');
}else{
$data = array('id_berita'=>cetak($this->input->post('a')),
'nama_komentar'=>cetak($this->input->post('b')),
'url'=>cetak($this->input->post('c')),
'isi_komentar'=>cetak($this->input->post('d')),
'tgl'=>date('Y-m-d'),
'jam_komentar'=>date('H:i:s'),
'aktif'=>'N',
'email'=>cetak($this->input->post('e')));
$this->model_berita->insert('komentar',$data);
}
redirect('berita/detail/'.$row['judul_seo'].'#listcomment');
}
}
Terakhir Kita buat form Komentar dan menampilkan Komentar dibawah tiap berita pada web UIR/kampus :
<?php
$baca = $record['dibaca']+1;
$total_komentar = $this->model_berita->view_where('komentar',array('id_berita' => $record['id_berita']))->num_rows(); if ($total_komentar>='1'){ ?>
<h1 class="page-title"><?php echo "Ada $total_komentar Komentar"; ?></h1><div class="hr-heading-list"></div>
<?php
$no = 1;
$komentar = $this->model_berita->view_where_ordering_limit('komentar',array('id_berita' => $record['id_berita']),'id_komentar','ASC',0,100); foreach ($komentar->result_array() as $kka) {
$isian=nl2br($kka['isi_komentar']); $komentarku = $isian;
echo "<div class='media-left'>";
if ($kka['email'] == ''){
echo "<img style='width:80px; height:80px' class='media-object img-thumbnail img-circle' src='".base_url()."asset/foto_user/blank.png' alt='avatar-1' />";
}else{
echo "<img style='width:80px; height:80px' class='media-object img-thumbnail img-circle' src='http://www.gravatar.com/avatar/$avatar.jpg?s=100'/>";
}
echo "
</div>
<div class='media-body'>
<strong class='user-nick'><a href='#'>$kka[nama_komentar]</a></strong>,
<span class='time-stamp'>".tgl_indo($kka['tgl']).", $kka[jam_komentar] WIB</span><br>
$komentarku
</div><hr style='margin:5px'>";
}
?>
<?php } ?>
<div class="post">
<div class="wpcf7" id="wpcf7-f10460-p5865-o1" lang="en-US" dir="ltr">
<div class="screen-reader-response"></div>
<?php
$attributes = array('id' => 'formku','novalidate'=>'novalidate','class'=>'wpcf7-form','onSubmit'=>'return validasi(this)'); echo form_open('berita/kirim_komentar',$attributes);
?>
<input type="hidden" name='a' value='<?php echo "$record[id_berita]"; ?>'>
<div class="field"><label>Nama Lengkap<span class="req">*</span></label>
<span class="wpcf7-form-control-wrap nama">
<input type="text" name="b" value="" size="40" aria-required="true" aria-invalid="false">
</span>
</div>
<div class="field"><label>Alamat Email <span class="req">*</span></label>
<span class="wpcf7-form-control-wrap email">
<input type="email" name="e" value="" size="40" aria-required="true" aria-invalid="false">
</span>
</div>
<div class="field"><label>Website <span class="req">*</span></label>
<span class="wpcf7-form-control-wrap email">
<input type="email" name="c" value="" size="40" aria-required="true" aria-invalid="false">
</span>
</div>
<div class="field"><label>Tulis Komentar <span class="req">*</span></label>
<span class="wpcf7-form-control-wrap detail-pertanyaan">
<textarea name="d" style='height:100px' aria-required="true" aria-invalid="false"></textarea>
</span>
</div>
<input type="hidden" name='cek' value=''>
<div class="field"><label> </label>
<input type="submit" value="Kirim" name='submit' class="wpcf7-form-control wpcf7-submit">
</div>
<div class="wpcf7-response-output wpcf7-display-none"></div></form></div>
<div class="tags"></div>
</div>
Selesai, dan kemudian silahkan coba berkomentar disana, berikut penampakan yg sudah kita cobakan,..