Menampilkan data konten dari database

Gambar 289. Here is how to display data that has been stored in the database

Menampilkan data konten dari database

Setelah sebelumnya kita bersama-sama membuat sebuah komponen testimonial, bagi anda yang belum membaca artikel sebelumnya silahkan anda baca artikel tentang Membuat komponen testimonial. Sekarang kita akan menampilkan data testimonial yang telah dibuat pengguna dan berhasil disimpan pada database. Dan untuk itu silahkan buka file testimonial.php pada root_dir/po-content/themes/theme_active/testimonial.php

Sekali lagi saya tekankan bahwa artikel ini merupakan artikel lanjutan dari artikel sebelumnya tentang Membuat komponen Testimonial.

Berikut adalah isi dari file tesebut:

<?=$this->layout('index');?>

<section id="page-title" class="page-title-mini" style="margin-top:-80px;">
  <div class="container clearfix">
    <ol class="breadcrumb">
      <li><a href="<?=BASE_URL;?>"><?=$this->e($front_home);?></a></li>
      <li><a href="<?=$this->e($social_url);?>"><?=$this->e($page_title);?></a></li>
    </ol>
  </div>
</section>

<section id="content">
  <div class="content-wrap">
    <div class="container clearfix">
      <div class="item-page" itemscope itemtype="https://schema.org/Article">
        <div itemprop="articleBody">
          <div id="portfolio" class="portfolio-masonry clearfix">
            <div class="col_full">
              <?=htmlspecialchars_decode($this->e($alertmsg));?>
              <form name="form-testimonial" action="<?=BASE_URL;?>/testimonial" method="post">
                <div class="col-md-4">
                  <div class="form-group">
                    <label for="name">Name</label>
                    <input type="text" name="name" class="form-control" id="name" value="<?=(isset($_POST['name']) ? $_POST['name'] : '');?>" placeholder="Name" required/>
                  </div>
                  <div class="form-group">
                    <label for="url">Website</label>
                    <input type="text" name="url" class="form-control" id="url" value="<?=(isset($_POST['url']) ? $_POST['url'] : '');?>" placeholder="https://your-domain.com" required/>
                  </div>
                  <div class="form-group">
                    <label for="picture">Picture</label><br/>
                    <!-- a href="#" data-toggle="modal" data-target=".login-modal" class="btn btn-default btn-small" style="color:#5775BF;border:1px #eee solid;"><b><i>Unggah Photo</i></b></a -->
                    <div class="input-group">
                      <input type="text" name="picture" class="form-control" id="picture" value="<?=(isset($_POST['picture']) ? $_POST['picture'] : '');?>" placeholder="picture" />
                    </div>
                  </div>
                </div>
                <div class="col-md-8">
                  <div class="form-group">
                    <label for="testimoni">Testimoni</label>
                    <textarea name="testimoni" class="form-control" id="testimoni" rows="3" placeholder="Testimoni" style="width:100%; height:250px;" required><?=(isset($_POST['testimoni']) ? $_POST['testimoni'] : '');?></textarea>
                  </div>
                  <button type="submit" class="button button-3d nomargin" style="float: right;">Submit</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Dan berikut adalah snippet untuk menampilkan data testimonial yang telah tersimpan di database:

<?php
  $testimonis = $this->pocore()->call->podb->from('testimonial')->orderBy('id_testimonial DESC')->limit(4)->fetchAll();
  foreach($testimonis as $testimoni) {
?>
Nama: <?=$testimoni['name'];?>
Website: <?=$testimoni['website'];?>
Testimoni: <?=htmlspecialchars_decode(html_entity_decode($testimonial['testimoni']));?>
Gambar default: <?=BASE_URL;?>/<?=DIR_CON;?>/uploads/<?=$testimoni['picture'];?>
Gambar medium: <?=BASE_URL;?>/<?=DIR_CON;?>/uploads/medium/medium_<?=$testimoni['picture'];?>
Gambar kecil(thumbs): <?=BASE_URL;?>/<?=DIR_CON;?>/thumbs/<?=$testimoni['picture'];?>
Link Untuk Detail Testimonial: <?=BASE_URL;?>/detailtestimonial/<?=$testimoni['seotitle'];?>
Penutup: <?php } ?>

Sehingga dengan penambahan class sesuai tema yang digunakan masing-masing, file testimonial.php akan menjadi seperti berikut:

<?=$this->layout('index');?>

<section id="page-title" class="page-title-mini" style="margin-top:-80px;">
  <div class="container clearfix">
    <ol class="breadcrumb">
      <li><a href="<?=BASE_URL;?>"><?=$this->e($front_home);?></a></li>
      <li><a href="<?=$this->e($social_url);?>"><?=$this->e($page_title);?></a></li>
    </ol>
  </div>
</section>

<section id="content">
  <div class="content-wrap">
    <div class="container clearfix">
      <div class="item-page">
        <div itemprop="articleBody">
          <div id="portfolio" class="portfolio-masonry clearfix">
            <div class="col_full">
              <?=htmlspecialchars_decode($this->e($alertmsg));?>
              <form name="form-testimonial" action="<?=BASE_URL;?>/testimonial" method="post">
                <div class="col-md-4">
                  <div class="form-group">
                    <label for="name">Name</label>
                    <input type="text" name="name" class="form-control" id="name" value="<?=(isset($_POST['name']) ? $_POST['name'] : '');?>" placeholder="Name" required/>
                  </div>
                  <div class="form-group">
                    <label for="website">Website</label>
                    <input type="text" name="website" class="form-control" id="website" value="<?=(isset($_POST['website']) ? $_POST['website'] : '');?>" placeholder="https://your-domain.com" required/>
                  </div>
                  <div class="form-group">
                    <label for="picture">Picture</label><br/>
                    <div class="input-group">
                      <input type="text" name="picture" class="form-control" id="picture" value="<?=(isset($_POST['picture']) ? $_POST['picture'] : '');?>" placeholder="picture" />
                    </div>
                  </div>
                </div>
                <div class="col-md-8">
                  <div class="form-group">
                    <label for="testimoni">Testimoni</label>
                    <textarea name="testimoni" class="form-control" id="testimoni" rows="3" placeholder="Testimoni" style="width:100%; height:250px;" required><?=(isset($_POST['testimoni']) ? $_POST['testimoni'] : '');?></textarea>
                  </div>
                  <button type="submit" class="button button-3d nomargin" style="float: right;">Submit</button>
                </div>
              </form>
            </div>
          </div>
          <hr class="devider40">
          <div class="col_full">
            <div class="fancy-title title-border"><h3><a href="<?=BASE_URL;?>/testimonial">Testimonials</a></h3></div>
            <div class="partners-carousel">
              <?php
                $testimonis = $this->pocore()->call->podb->from('testimonial')->orderBy('id_testimonial DESC')->limit(4)->fetchAll();
                foreach($testimonis as $testimoni) {
              ?>
              <div class="testimonial">
                <?php if ($this->e($testimoni['picture']) != '') { ?>
                <a title="<?=$testimoni['name'];?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimoni['seotitle'];?>">
                  <img class="img-circle" src="<?=BASE_URL;?>/<?=DIR_CON;?>/thumbs/<?=$testimoni['picture'];?>" alt="<?=$testimoni['name'];?>">
                </a>
                <?php } else { ?>
                <a title="<?=$testimoni['name'];?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimoni['seotitle'];?>">
                  <img class="img-circle" src="<?=BASE_URL.'/'.DIR_CON.'/uploads/avatar.jpg';?>" alt="<?=$testimoni['name'];?> ">
                </a>
                <?php } ?>
                <a title="<?=$testimoni['name'];?>" href="<?=$testimoni['website'];?>" target="_blank" >
                  <h4><?=$testimoni['name'];?></h4>
                </a>
                <p><?=$this->pocore()->call->postring->cuthighlight('testimoni', html_entity_decode($testimoni['testimoni']), '100');?> ...</p>
                <a title="<?=$this->e($front_testimonial_readmore);?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimoni['seotitle'];?>">
                  <?=$this->e($front_testimonial_readmore);?>
                </a>
              </div>
            <?php } ?>
            </div>
            <div class="col-md-12 text-center color_section" style="margin-top:30px;">
              <ul class="pagination nobottommargin">  
                <?php
                  $totaldata = $this->pocore()->call->podb->from('testimonial')->count();
                  $totalpage = $this->pocore()->call->popaging->totalPage($totaldata, $limit);
                  echo $this->pocore()->call->popaging->navPage($this->e($page), $totalpage, BASE_URL, 'testimonial', 'page', '1', $this->e($front_paging_prev), $this->e($front_paging_next));
                ?>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Agar halaman testimonial tidak mengalami error maka kita harus menambahkan folder lang/testimonial/ yang didalamnya terdapat id.php dan gb.php pada root_dir/po-content/lang/testimonial/id.php-gb.php

Berikut adalah isi file id.php pada root_dir/po-content/lang/testimonial/:

<?php
/**
 *
 * - PopojiCMS Testimonial Language
 *
 * - File : id.php
 * - Version : 1.0
 * - Author : Jenuar Dalapang
 * - Modification : Muhammad Ridho
 * - License : MIT License
 *
*/

$_['component_name'] = 'Testimonial';
$_['testimonial_action'] = 'Tindakan';
$_['testimonial_view'] = 'Lihat';
$_['testimonial_title'] = 'Nama | Link';
$_['testimonial_title_2'] = 'Nama';
$_['testimonial_seotitle'] = 'Judul SEO';
$_['testimonial_content'] = 'Testimoni';
$_['testimonial_picture'] = 'Gambar';
$_['testimonial_url'] = 'Link Pengguna';
$_['testimonial_active'] = 'Aktif';
$_['testimonial_not_active'] = 'Tidak Aktif';
$_['testimonial_action'] = 'Tindakan';
$_['testimonial_addnew'] = 'Tambah testimonial';
$_['testimonial_edit'] = 'Update testimonial';
$_['testimonial_date'] = 'Tanggal Testimoni';
$_['testimonial_time'] = 'Waktu Tayang Testimoni';
$_['testimonial_by'] = 'Oleh';
$_['testimonial_share'] = 'Bagikan';
$_['testimonial_message_1'] = 'Testimonial telah berhasil ditambahkan';
$_['testimonial_message_2'] = 'Testimonial telah berhasil diperbarui';
$_['testimonial_message_3'] = 'Testimonial telah berhasil dihapus';
$_['testimonial_message_4'] = 'Kesalahan menambah data testimonial baru';
$_['testimonial_message_5'] = 'Kesalahan memperbarui data testimonial';
$_['testimonial_message_6'] = 'Kesalahan menghapus data testimonial';
$_['testimonial_picture_2'] = 'Tidak Ada Gambar Terpilih';
$_['testimonial_picture_3'] = 'Tidak Ada Gambar Preview';
$_['testimonial_picture_4'] = 'Jika gambar tidak diganti, tidak perlu memilih pilihan di bawah ini.';
$_['testimonial_picture_5'] = 'Gambar Terpilih';
$_['testimonial_picture_6'] = 'Ada Gambar Terpilih';
$_['testimonial_back_to_testimonial'] = 'Kembali Ke testimonial';
$_['testimonial_file'] = 'Unggah File';
$_['testimonial_import_help'] = 'Script ini menerima ukuran file max. 10 MB. Jika Anda tidak dapat mengunggah harap verifikasi konfigurasi server Anda untuk menerima ukuran file Anda.';
$_['testimonial_message_7'] = 'Kesalahan mengimport data testimonial';
$_['testimonial_message_8'] = 'testimonial telah berhasil diimportkan';
$_['testimonial_read'] = 'Tandai Sudah di Baca';
$_['testimonial_notread'] = 'Tandai Belum di Baca';

$_['front_testimonial'] = 'Testimonial';
$_['front_testimonial_title'] = 'Testimonial';
$_['front_testimonial_not_found'] = 'Testimonial Tidak Ditemukan';
$_['front_search_title'] = 'Pencarian';
$_['front_search_not_found'] = 'Pencarian Tidak Ditemukan';

$_['front_testimonial_readmore'] = 'Testimoni Selengkapnya';
$_['front_testimonial_error'] = 'Error! Silahkan cek dan input data dengan benar!';
$_['front_testimonial_success'] = 'Terimakasih...! Agar photo anda dapat tampilkan dalam testimoni, silahkan kirimkan photo tersebut kepada kami melalui email atau chat facebook!';

Berikut adalah isi file gb.php pada root_dir/po-content/lang/testimonial/:

<?php
/**
 *
 * - PopojiCMS Testimonial Language
 *
 * - File : gb.php
 * - Version : 1.0
 * - Author : Jenuar Dalapang
 * - Modification : Muhammad Ridho
 * - License : MIT License
 *
*/

$_['component_name'] = 'Testimonials';
$_['testimonial_action'] = 'Action';
$_['testimonial_view'] = 'View';
$_['testimonial_title'] = 'Name | Link';
$_['testimonial_title_2'] = 'Name';
$_['testimonial_seotitle'] = 'SEO Title';
$_['testimonial_content'] = 'Testimoni';
$_['testimonial_picture'] = 'Picture';
$_['testimonial_active'] = 'Active';
$_['testimonial_not_active'] = 'Not Active';
$_['testimonial_action'] = 'Action';
$_['testimonial_addnew'] = 'Add testimonial';
$_['testimonial_edit'] = 'Update testimonial';
$_['testimonial_date'] = 'Publish Date';
$_['testimonial_time'] = 'Publish Time';
$_['testimonial_by'] = 'By';
$_['testimonial_share'] = 'Share';
$_['testimonial_message_1'] = 'Testimonial has been successfully added';
$_['testimonial_message_2'] = 'Testimonial has been successfully updated';
$_['testimonial_message_3'] = 'Testimonial has been successfully deleted';
$_['testimonial_message_4'] = 'Error added new testimonial data';
$_['testimonial_message_5'] = 'Error updated testimonial data';
$_['testimonial_message_6'] = 'Error deleted testimonial data';
$_['testimonial_picture_2'] = 'No Image Selected';
$_['testimonial_picture_3'] = 'No Existing Image Preview';
$_['testimonial_picture_4'] = 'If the image is not replaced, do not choose any option below.';
$_['testimonial_picture_5'] = 'Image Selected';
$_['testimonial_picture_6'] = 'Existing Image Preview';
$_['testimonial_add_category'] = 'Add New Category';
$_['testimonial_refresh_category'] = 'Refresh';
$_['testimonial_add_tag'] = 'Add New Tag';
$_['testimonial_oauth_message_1'] = 'Twitter status has been successfully updated';
$_['testimonial_oauth_message_2'] = 'Error updated twitter status';
$_['testimonial_oauth_message_3'] = 'Facebook status has been successfully updated';
$_['testimonial_oauth_message_4'] = 'Error updated facebook status';
$_['testimonial_subscribe_message_1'] = 'testimonial has been successfully send to subscriber';
$_['testimonial_import'] = 'Import from WP and Old PopojiCMS';
$_['testimonial_import_from'] = 'From';
$_['testimonial_back_to_testimonial'] = 'Back To testimonial';
$_['testimonial_file'] = 'Upload File';
$_['testimonial_import_help'] = 'This script accepts file size max. 10 MB. If you can't upload please verify your server configurations to accepted the size of your file.';
$_['testimonial_message_7'] = 'Error imported testimonial data';
$_['testimonial_message_8'] = 'testimonial has been successfully imported';
$_['orderproduct_read'] = 'Mark as read';
$_['orderproduct_notread'] = 'Mark Yet in read';

$_['front_testimonial'] = 'Testimonial';
$_['front_testimonial_title'] = 'Testimonial';
$_['front_testimonial_not_found'] = 'Testimonial Not Found';
$_['front_search_title'] = 'Search';
$_['front_search_not_found'] = 'Search Not Found';

$_['front_testimonial_readmore'] = 'Readmore Testimoni';
$_['front_testimonial_error'] = 'Error! Please check and input data correctly!.';
$_['front_testimonial_success'] = 'Thank you ...! In order for your photo can show in a testimonial, please send the photo to us via email or facebook chat!';

Untuk menghindari error 404 Pages Not Found saat link pada halaman testimonial di klik maka kita harus menambahkan element detailtestimonial.php pada root_dir/po-content/themes/theme_active/detailtestimonial.php
Dan untuk penambahan element detailtestimonial.php maka kita juga harus melakukan penambahan script pada file testimonial.php yang berada pada root_dir/po-content/component/testimonial/testimonial.php, berikut adalah isi dari file testimonial tersebut:

<?php
/*
 *
 * - PopojiCMS Front End File
 *
 * - File : testimonial.php
 * - Version : 1.0
 * - Author : Clark
 * - License : MIT License
 *
 *
 * Ini adalah file php yang di gunakan untuk menangani proses di bagian depan untuk halaman testimonial.
 * This is a php file for handling front end process for testimonial page.
 *
*/

/**
 * Router untuk menampilkan request halaman testimonial.
 *
 * Router for display request in testimonial page.
 *
*/
$router->match('GET|POST', '/testimonial', function() use ($core, $templates) {
  $alertmsg = '';
  $lang = $core->setlang('testimonial', WEB_LANG);
  if (!empty($_POST)) {
    if (!empty($_POST['name'])) {
      $core->poval->filter_rules(array(
        'name' => 'trim|sanitize_string',
        'job' => 'trim|sanitize_string',
        'testimoni' => 'trim|sanitize_string',
        'rating' => 'trim|sanitize_string',
        'url' => 'trim|sanitize_string',
        'date' => 'trim|sanitize_string',
        'active' => 'trim|sanitize_string',
      ));
      $validated_data = $core->poval->run($_POST);
      if ($validated_data === false) {
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-warning" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Error! Please check again before submit.
          </div>
        </div>';
      } else {
      $data = array(
        'name' => $_POST['name'],
        'seotitle' => $core->postring->seo_title($_POST['name']),
        'job' => $_POST['job'],
        'testimoni' => $_POST['testimoni'],
        'rating' => $_POST['rating'],
        'url' => $_POST['url'],
        'date' => $_POST['date'],
      );
      $query = $core->podb->insertInto('testimonial')->values($data);
      $query->execute();
      unset($_POST);
      $alertmsg = '<div id="contact-form-result">
        <div class="alert alert-success" role="alert">
          <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          Thank you, your data successfully submited.
        </div>
      </div>';
    }
    } else {
      $alertmsg = '<div class="alert alert-warning" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        Error! '.ucfirst('name').' is required.
      </div>';
    }
  }
  $info = array(
    'page_title' => 'Testimonial',
    'page_desc' => 'Testimonial',
    'page_key' => 'Testimonial',
    'social_mod' => 'Testimonial',
    'social_name' => $core->posetting[0]['value'],
    'social_url' => $core->posetting[1]['value'].'/testimonial',
    'social_title' => 'Testimonial',
    'social_desc' => 'Testimonial',
    'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png',
    'page' => '1',
    'alertmsg' => $alertmsg
  );
  $adddata = array_merge($info, $lang);
  $templates->addData(
    $adddata
  );
  echo $templates->render('testimonial', compact('testimonial', 'lang'));
});

/**
 * Router untuk menampilkan request halaman testimonial.
 *
 * Router for display request in testimonial page.
 *
*/
$router->match('GET|POST', '/testimonial/page/(d+)', function($page) use ($core, $templates) {
  $alertmsg = '';
  $lang = $core->setlang('testimonial', WEB_LANG);
  if (!empty($_POST)) {
    if (!empty($_POST['name'])) {
      $core->poval->filter_rules(array(
        'name' => 'trim|sanitize_string',
        'job' => 'trim|sanitize_string',
        'testimoni' => 'trim|sanitize_string',
        'rating' => 'trim|sanitize_string',
        'url' => 'trim|sanitize_string',
        'picture' => 'trim|sanitize_string',
        'date' => 'trim|sanitize_string',
        'active' => 'trim|sanitize_string',
      ));
      $validated_data = $core->poval->run($_POST);
      if ($validated_data === false) {
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-warning" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Error! Please check again before submit.
          </div>
        </div>';
      } else {
        $data = array(
          'name' => $_POST['name'],
          'seotitle' => $core->postring->seo_title($_POST['name']),
          'job' => $_POST['job'],
          'testimoni' => $_POST['testimoni'],
          'rating' => $_POST['rating'],
          'url' => $_POST['url'],
          'picture' => $_POST['picture'],
          'date' => $_POST['date'],
        );
        $query = $core->podb->insertInto('testimonial')->values($data);
        $query->execute();
        unset($_POST);
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-success" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Thank you, your data successfully submited.
          </div>
        </div>';
      }
    } else {
      $alertmsg = '<div class="alert alert-warning" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        Error! '.ucfirst('name').' is required.
      </div>';
    }
  }
  $info = array(
    'page_title' => 'Testimonial',
    'page_desc' => 'Testimonial',
    'page_key' => 'Testimonial',
    'social_mod' => 'Testimonial',
    'social_name' => $core->posetting[0]['value'],
    'social_url' => $core->posetting[1]['value'].'/testimonial',
    'social_title' => 'Testimonial',
    'social_desc' => 'Testimonial',
    'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png',
    'page' => $page,
    'alertmsg' => $alertmsg
  );
  $adddata = array_merge($info, $lang);
  $templates->addData(
    $adddata
  );
  echo $templates->render('testimonial', compact('testimonial', 'lang'));
});

Tambahkan router untuk menampilkan halaman detailtestimonial pada script file diatas, berikut adalah router untuk detailtestimonial:

/**
 * Router untuk menampilkan request halaman detailtestimonial.
 *
 * Router for display request in detailtestimonial page.
 *
 * $seotitle = string [a-z0-9_-]
*/
$router->match('GET|POST', '/detailtestimonial/([a-z0-9_-]+)', function($seotitle) use ($core, $templates) {
  $lang = $core->setlang('testimonial', WEB_LANG);
  $testimonial = $core->podb->from('testimonial')->where('seotitle', $seotitle)->limit(1)->fetch();
  if ($testimonial) {
    $info = array(
      'page_title' => $testimonial['name'],
      'page_desc' => $core->posetting[2]['value'],
      'page_key' => $core->posetting[3]['value'],
      'social_mod' => $lang['front_testimonial'].' '.$testimonial['name'],
      'social_name' => $core->posetting[0]['value'],
      'social_url' => $core->posetting[1]['value'].'/detailtestimonial/'.$testimonial['seotitle'],
      'social_title' => $core->posetting[0]['value'],
      'social_desc' => $core->posetting[2]['value'],
      'social_img' => BASE_URL.'/'.DIR_CON.'/uploads/medium/medium_'.$testimonial['picture'],
    );
    $adddata = array_merge($info, $lang);
    $templates->addData(
      $adddata
    );
    echo $templates->render('detailtestimonial', compact('lang', 'testimonial'));
  } else {
    $info = array(
      'page_title' => $lang['front_testimonial_not_found'],
      'page_desc' => $core->posetting[2]['value'],
      'page_key' => $core->posetting[3]['value'],
      'social_mod' => $lang['front_testimonial'],
      'social_name' => $core->posetting[0]['value'],
      'social_url' => $core->posetting[1]['value'],
      'social_title' => $lang['front_testimonial_not_found'],
      'social_desc' => $core->posetting[2]['value'],
      'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png'
    );
    $adddata = array_merge($info, $lang);
    $templates->addData(
      $adddata
    );
    echo $templates->render('404', compact('lang'));
  }
});

Sehingga secara keseluruhan file testimonial.php yang berada pada root_dir/po-content/component/testimonial/testimonial.php akan menjadi seperti berikut:

<?php
/*
 *
 * - PopojiCMS Front End File
 *
 * - File : testimonial.php
 * - Version : 1.0
 * - Author : Clark
 * - License : MIT License
 *
 *
 * Ini adalah file php yang di gunakan untuk menangani proses di bagian depan untuk halaman testimonial.
 * This is a php file for handling front end process for testimonial page.
 *
*/

/**
 * Router untuk menampilkan request halaman testimonial.
 *
 * Router for display request in testimonial page.
 *
*/
$router->match('GET|POST', '/testimonial', function() use ($core, $templates) {
  $alertmsg = '';
  $lang = $core->setlang('testimonial', WEB_LANG);
  if (!empty($_POST)) {
    if (!empty($_POST['name'])) {
      $core->poval->filter_rules(array(
        'name' => 'trim|sanitize_string',
        'job' => 'trim|sanitize_string',
        'testimoni' => 'trim|sanitize_string',
        'rating' => 'trim|sanitize_string',
        'url' => 'trim|sanitize_string',
        'date' => 'trim|sanitize_string',
        'active' => 'trim|sanitize_string',
      ));
      $validated_data = $core->poval->run($_POST);
      if ($validated_data === false) {
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-warning" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Error! Please check again before submit.
          </div>
        </div>';
      } else {
      $data = array(
        'name' => $_POST['name'],
        'seotitle' => $core->postring->seo_title($_POST['name']),
        'job' => $_POST['job'],
        'testimoni' => $_POST['testimoni'],
        'rating' => $_POST['rating'],
        'url' => $_POST['url'],
        'date' => $_POST['date'],
      );
      $query = $core->podb->insertInto('testimonial')->values($data);
      $query->execute();
      unset($_POST);
      $alertmsg = '<div id="contact-form-result">
        <div class="alert alert-success" role="alert">
          <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          Thank you, your data successfully submited.
        </div>
      </div>';
    }
    } else {
      $alertmsg = '<div class="alert alert-warning" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        Error! '.ucfirst('name').' is required.
      </div>';
    }
  }
  $info = array(
    'page_title' => 'Testimonial',
    'page_desc' => 'Testimonial',
    'page_key' => 'Testimonial',
    'social_mod' => 'Testimonial',
    'social_name' => $core->posetting[0]['value'],
    'social_url' => $core->posetting[1]['value'].'/testimonial',
    'social_title' => 'Testimonial',
    'social_desc' => 'Testimonial',
    'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png',
    'page' => '1',
    'alertmsg' => $alertmsg
  );
  $adddata = array_merge($info, $lang);
  $templates->addData(
    $adddata
  );
  echo $templates->render('testimonial', compact('testimonial', 'lang'));
});

/**
 * Router untuk menampilkan request halaman testimonial.
 *
 * Router for display request in testimonial page.
 *
*/
$router->match('GET|POST', '/testimonial/page/(d+)', function($page) use ($core, $templates) {
  $alertmsg = '';
  $lang = $core->setlang('testimonial', WEB_LANG);
  if (!empty($_POST)) {
    if (!empty($_POST['name'])) {
      $core->poval->filter_rules(array(
        'name' => 'trim|sanitize_string',
        'job' => 'trim|sanitize_string',
        'testimoni' => 'trim|sanitize_string',
        'rating' => 'trim|sanitize_string',
        'url' => 'trim|sanitize_string',
        'picture' => 'trim|sanitize_string',
        'date' => 'trim|sanitize_string',
        'active' => 'trim|sanitize_string',
      ));
      $validated_data = $core->poval->run($_POST);
      if ($validated_data === false) {
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-warning" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Error! Please check again before submit.
          </div>
        </div>';
      } else {
        $data = array(
          'name' => $_POST['name'],
          'seotitle' => $core->postring->seo_title($_POST['name']),
          'job' => $_POST['job'],
          'testimoni' => $_POST['testimoni'],
          'rating' => $_POST['rating'],
          'url' => $_POST['url'],
          'picture' => $_POST['picture'],
          'date' => $_POST['date'],
        );
        $query = $core->podb->insertInto('testimonial')->values($data);
        $query->execute();
        unset($_POST);
        $alertmsg = '<div id="contact-form-result">
          <div class="alert alert-success" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            Thank you, your data successfully submited.
          </div>
        </div>';
      }
    } else {
      $alertmsg = '<div class="alert alert-warning" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        Error! '.ucfirst('name').' is required.
      </div>';
    }
  }
  $info = array(
    'page_title' => 'Testimonial',
    'page_desc' => 'Testimonial',
    'page_key' => 'Testimonial',
    'social_mod' => 'Testimonial',
    'social_name' => $core->posetting[0]['value'],
    'social_url' => $core->posetting[1]['value'].'/testimonial',
    'social_title' => 'Testimonial',
    'social_desc' => 'Testimonial',
    'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png',
    'page' => $page,
    'alertmsg' => $alertmsg
  );
  $adddata = array_merge($info, $lang);
  $templates->addData(
    $adddata
  );
  echo $templates->render('testimonial', compact('testimonial', 'lang'));
});


/**
 * Router untuk menampilkan request halaman detailtestimonial.
 *
 * Router for display request in detailtestimonial page.
 *
 * $seotitle = string [a-z0-9_-]
*/
$router->match('GET|POST', '/detailtestimonial/([a-z0-9_-]+)', function($seotitle) use ($core, $templates) {
  $lang = $core->setlang('testimonial', WEB_LANG);
  $testimonial = $core->podb->from('testimonial')->where('seotitle', $seotitle)->limit(1)->fetch();
  if ($testimonial) {
    $info = array(
      'page_title' => $testimonial['name'],
      'page_desc' => $core->posetting[2]['value'],
      'page_key' => $core->posetting[3]['value'],
      'social_mod' => $lang['front_testimonial'].' '.$testimonial['name'],
      'social_name' => $core->posetting[0]['value'],
      'social_url' => $core->posetting[1]['value'].'/detailtestimonial/'.$testimonial['seotitle'],
      'social_title' => $core->posetting[0]['value'],
      'social_desc' => $core->posetting[2]['value'],
      'social_img' => BASE_URL.'/'.DIR_CON.'/uploads/medium/medium_'.$testimonial['picture'],
    );
    $adddata = array_merge($info, $lang);
    $templates->addData(
      $adddata
    );
    echo $templates->render('detailtestimonial', compact('lang', 'testimonial'));
  } else {
    $info = array(
      'page_title' => $lang['front_testimonial_not_found'],
      'page_desc' => $core->posetting[2]['value'],
      'page_key' => $core->posetting[3]['value'],
      'social_mod' => $lang['front_testimonial'],
      'social_name' => $core->posetting[0]['value'],
      'social_url' => $core->posetting[1]['value'],
      'social_title' => $lang['front_testimonial_not_found'],
      'social_desc' => $core->posetting[2]['value'],
      'social_img' => $core->posetting[1]['value'].'/'.DIR_INC.'/images/favicon.png'
    );
    $adddata = array_merge($info, $lang);
    $templates->addData(
      $adddata
    );
    echo $templates->render('404', compact('lang'));
  }
});

Silahkan istirahat sejenak dan minum kopi anda untuk menghilangkan ketegangan. Karena tutorial ini belum selesai, kita masih harus membuat sebuah element detailtestimonial.php untuk menampilkan detail testimoni dari masing-masing pemberi testimoni tersebut.
Baik... mari kita lanjutkan. Sekarang silahkan buat sebuah elemen file detailtestimonial.php pada root_dir/po-content/themes/theme_active/detailtestimonial.php, Dan berikut adalah script pada elemen detailtestimonial berdasarkan class dari tema Chingsy:

<?=$this->layout('index');?>

<section id="page-title" class="page-title-mini" style="margin-top:-80px;">
  <div class="container clearfix">
    <ol class="breadcrumb">
      <li><a href="<?=BASE_URL;?>"><?=$this->e($front_home);?></a></li>
      <li><a href="<?=BASE_URL;?>/testimonial">Testimonial</a></li>
      <li><a href="<?=$this->e($social_url);?>"><?=$this->e($page_title);?></a></li>
    </ol>
  </div>
</section>

<section id="content">
  <div class="content-wrap">
    <div class="container clearfix">
      <div class="item-page" itemscope itemtype="https://schema.org/Article">
        <div itemprop="articleBody">
          <div id="portfolio" class="portfolio-masonry clearfix">
            <div class="col_full bottommargin-lg">
              <div class="table-responsive">
                <table class="table table-bordered">
                  <tbody>
                    <tr>
                      <td rowspan="7" class="text-center">
                        <div class="fancy-title title-border">
                          <a href="<?=$this->e($social_url);?>"> <h2><?=$this->e($page_title);?></h2> </a>
                        </div>
                        <div class="widget testimoni-widget">
                          <?php if ($this->e($testimonial['picture']) != '') { ?>
                          <a title="<?=$testimonial['name'];?>" href="<?=BASE_URL;?>/<?=DIR_CON;?>/uploads/testimonial/<?=$testimonial['picture'];?>" data-gal="prettyPhoto">
                            <img class="img-circle" src="<?=BASE_URL;?>/<?=DIR_CON;?>/thumbs/testimonial/<?=$testimonial['picture'];?>" alt="<?=$testimonial['name'];?>">
                          </a>
                          <?php } else { ?>
                          <a title="<?=$testimonial['name'];?>" href="<?=BASE_URL.'/'.DIR_CON.'/uploads/avatar.jpg';?>" data-gal="prettyPhoto">
                            <img class="img-circle" src="<?=BASE_URL.'/'.DIR_CON.'/uploads/avatar.jpg';?>" alt="<?=$testimonial['name'];?>">
                          </a>
                          <?php } ?>
                        </div>
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <div class="col-md-9 testimoni-widget" style="margin-top:30px;"><br/>
                          <?=htmlspecialchars_decode(html_entity_decode($testimonial['testimoni']));?>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="clearfix"></div>
            <div class="col_full topmargin-lg">
              <div class="fancy-title title-border"><h3><a href="<?=BASE_URL;?>/testimonial">Testimonials</a></h3></div>
              <h4><?=$this->e($front_testimonial_like);?> <a href="<?=BASE_URL;?>/testimonial"> <?=$this->e($front_testimonial_like_create);?></a></h4>
              <div class="partners-carousel">
                <?php
                  $testimonials = $this->pocore()->call->podb->from('testimonial')->orderBy('id_testimonial DESC')->limit(12)->fetchAll();
                  foreach($testimonials as $testimonial) {
                ?>
                <div style="background:#eee; padding:5px; border:3px #fff solid;">
                  <div class="testimonial">
                    <?php if ($this->e($testimonial['picture']) != '') { ?>
                    <a title="<?=$testimonial['name'];?> - <?=$testimonial['job'];?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimonial['seotitle'];?>">
                      <img class="img-circle" src="<?=BASE_URL;?>/<?=DIR_CON;?>/thumbs/testimonial/<?=$testimonial['picture'];?>" alt="<?=$testimonial['name'];?>">
                    </a>
                    <?php } else { ?>
                    <a title="<?=$testimonial['name'];?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimonial['seotitle'];?>">
                      <img class="img-circle" src="<?=BASE_URL.'/'.DIR_CON.'/uploads/avatar.jpg';?>" alt="<?=$testimonial['name'];?>">
                    </a>
                    <?php } ?>
                    <a href="<?=$testimonial['url'];?>" target="_blank" rel="external nofollow">
                      <h4><?=$testimonial['name'];?></h4>
                    </a>
                  </div>
                  <p><?=$this->pocore()->call->postring->cuthighlight('testimonial', html_entity_decode($testimonial['testimoni']), '100');?> ...</p>
                  <a title="<?=$this->e($front_testimonial_readmore);?>" href="<?=BASE_URL;?>/detailtestimonial/<?=$testimonial['seotitle'];?>"><?=$this->e($front_testimonial_readmore);?></a>
                </div>
                <?php } ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Baca artikel lanjutanya pada artikel Membuat unggah File atau Gambar Pada Sebuah Formulir.

Karena artikel ini telah mencapai batas konsentrasi anda, maka untuk penambahan unggah gambar/file akan saya bahas pada artikel selanjutnya. Untuk membahas masalah yang anda hadapi silahkan buat sebuah komentar, pertanyaan terkait artikel ini melalui media lain tidak dapatt saya tanggapi. Agar anda mendapat pemberitahuan update artikel lanjutan silahkan berlangganan gratis melalui formulir subscribe! Terimakasih....

Post Terkait

Cara Menampilkan Widget Iklan

Cara Menampilkan Widget  iklan dari Komponen Iklan yang Telah dibuat Untuk Menampilkan Widget Iklan dari komponen yang telah dibuat sebelumnya...

Author

Administrator

14 Maret 2018

Hey..... Apa kabar? Semua artikel dan layanan yang kami sediakan di sini semata-mata untuk kepentingan pengguna dan klien. Jadi jika Anda merasa membutuhkan pelayanan kami silahkan jangan ragu untuk menghubungi. Kami juga bersedia untuk melayani konsultasi online melalui media sosial, melalui komentar dan melalui halaman testimonial yang telah kami sediakan. Selain itu Anda juga dapat menggunakan kontak form yang tersedia.

Jika apa yang anda dapatkan dari situs ini bermanfaat, silahkan dukung dengan like dan share . Terimakasih telah berkunjung, silahkan kembali kapanpun anda merasa membutuhkan layanan yang kami sediakan.

Ingin berbagi dengan multibisnisindo dan memberikan kontribusi....? Tulis pengalamanmu Di Sini

Terimakasih
Best Regard

Tidak ada komentar terkait posting ini, Ingin memberi komentar?