mumunotes

  • Home
  • Contact Us

Thursday, 5 November 2015

Export Data to PDF with MPDF Extension

 mumunotesss     10:12     Yii, Yii2     No comments   

Hello every body, Assalamualaikum Wr. Wb.
Nearly 1 month, i don't share anything in my blog. And this section, i will post about "Export Data to PDF with MPDF Extension". Ok, let's begin.
First, please open composer.json file and change with following this content.
others code
"require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.4",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
"himiklab/yii2-recaptcha-widget" : "*",
"abhi1693/yii2-sms": "2.0.0",
"robregonm/yii2-pdf": "*",
"mpdf/mpdf":"*",
         },
others code
Then, please update your composer.json. A new vendor(mpdf) has instaled.
Create a new file as main1.php in views/layouts and add this code.
<?php
use yii\helpers\Html;
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<div class="container">
<?= $content ?>
</div>
</div>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
Create a new file as template.php in views/site and add this code.
<?php
use yii\helpers\Html;
use yii\grid\GridView;
?>
<style type="text/css">
table {
*border-collapse: collapse; /* IE7 and lower */
border-spacing: 0;
width: 100%;  
}
.zebra td, .zebra th {
padding: 10px;
border-bottom: 1px solid #f2f2f2;  
}

.zebra tbody tr:nth-child(even) {
background: #f5f5f5;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
-moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;
box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;      
}

.zebra th {
text-align: left;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
border-bottom: 1px solid #ccc;
background-color: #eee;
background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#eee));
background-image: -webkit-linear-gradient(top, #f5f5f5, #eee);
background-image:    -moz-linear-gradient(top, #f5f5f5, #eee);
background-image:     -ms-linear-gradient(top, #f5f5f5, #eee);
background-image:      -o-linear-gradient(top, #f5f5f5, #eee);
background-image:         linear-gradient(top, #f5f5f5, #eee);
}

.zebra th:first-child {
-moz-border-radius: 6px 0 0 0;
-webkit-border-radius: 6px 0 0 0;
border-radius: 6px 0 0 0;
}

.zebra th:last-child {
-moz-border-radius: 0 6px 0 0;
-webkit-border-radius: 0 6px 0 0;
border-radius: 0 6px 0 0;
}

.zebra th:only-child{
-moz-border-radius: 6px 6px 0 0;
-webkit-border-radius: 6px 6px 0 0;
border-radius: 6px 6px 0 0;
}

.zebra tfoot td {
border-bottom: 0;
border-top: 1px solid #fff;
background-color: #f1f1f1;
}

.zebra tfoot td:first-child {
-moz-border-radius: 0 0 0 6px;
-webkit-border-radius: 0 0 0 6px;
border-radius: 0 0 0 6px;
}

.zebra tfoot td:last-child {
-moz-border-radius: 0 0 6px 0;
-webkit-border-radius: 0 0 6px 0;
border-radius: 0 0 6px 0;
}

.zebra tfoot td:only-child{
-moz-border-radius: 0 0 6px 6px;
-webkit-border-radius: 0 0 6px 6px
border-radius: 0 0 6px 6px
}
</style>
<table class="zebra" style="margin:auto; width:100%;">
<thead>
<tr>
<th>No</th>
<th>NIM</th>
<th>NAMA</th>
<th>JURUSAN</th>
<th>ANGKATAN</th>
<th>ALAMAT</th>
<th>FOTO</th>
</tr>
</thead>
<?php
$i=1;
foreach($model as $data){
echo '
<tr>
<td>'.$i.'</td>
<td>'.$data['nim'].'</td>
<td>'.$data['nama'].'</td>
<td>'.$data['jurusan'].'</td>
<td>'.$data['angkatan'].'</td>
<td>'.$data['alamat'].'</td>
<td><img src="'.Yii::$app->request->baseUrl.'/uploads/'.$data['foto'].'" width="100px"></td>
</tr>
';
$i++;
}
?>
</table>

Oke, next open your SiteController.php file and create a new action as Exportpdf like this code.
public function actionExportpdf() {
$this->layout='main1';
$model = Mahasiswa::find()->All();
$mpdf=new mPDF();
$mpdf->WriteHTML($this->renderPartial('template',['model'=>$model]));
$mpdf->Output('MyPDF.pdf', 'D');
exit;
}
And the last, add url ('/site/exportpdf') to your menu.
Well, now it's time to try it. Access site/exportpdf url on your application!


The result.

It's easy, isn't? Now you can implement this method to your application project. So good luck. Thank you. Wassalamualaikum Wr. Wb.


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Wednesday, 2 September 2015

Import Data from CSV File to Database Without Extension in Yii2

 mumunotesss     10:27     Yii, Yii2     No comments   

Hello everybody, Assalamualaikum Wr. Wb. Nearly 1 month I don't publish article. Now, I publish an article about "Import Data from CSV File to Database Without Extension in Yii2".
Let's go.
First, create a model class with name CsvForm.php in models folder and add the code below to it.
<?php

namespace app\models;

use Yii;
use yii\base\Model;

class CsvForm extends Model{
    public $file;
   
    public function rules(){
        return [
            [['file'],'required'],
            [['file'],'file','extensions'=>'csv','maxSize'=>1024 * 1024 * 5],
        ];
    }
   
    public function attributeLabels(){
        return [
            'file'=>'Select File',
        ];
    }
}
Then, open your SiteController.php file and change with following the content.
public function actionUpload(){
    $model = new CsvForm;
   
    if($model->load(Yii::$app->request->post())){
        $file = UploadedFile::getInstance($model,'file');
        $filename = 'Data.'.$file->extension;
        $upload = $file->saveAs('uploads/'.$filename);
        if($upload){
            define('CSV_PATH','uploads/');
            $csv_file = CSV_PATH . $filename;
            $filecsv = file($csv_file);
            print_r($filecsv);
            foreach($filecsv as $data){
                $modelnew = new Mahasiswa;
                $hasil = explode(",",$data);
                $nim = $hasil[0];
                $nama = $hasil[1];
                $jurusan = $hasil[2];
                $angkatan = $hasil[3];
                $alamat = $hasil[4];
                $foto = $hasil[5];
                $modelnew->nim = $nim;
                $modelnew->nama = $nama;
                $modelnew->jurusan = $jurusan;
                $modelnew->angkatan = $angkatan;
                $modelnew->alamat = $alamat;
                $modelnew->foto = $foto;
                $modelnew->save();
            }
            unlink('uploads/'.$filename);
            return $this->redirect(['site/index']);
        }
    }else{
        return $this->render('upload',['model'=>$model]);
    }
}
Create a view file in site folder as upload.php and add this content
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

?>

<?php $form = ActiveForm::begin(['options' => ['enctype'=>'multipart/form-data']]); ?>
    <?= $form->field($model,'file')->fileInput() ?>
   
    <div class="form-group">
        <?= Html::submitButton('Save',['class'=>'btn btn-primary']) ?>
    </div>
<?php ActiveForm::end(); ?>

Don't forget to create uploads folder in web folder and add menu to access site/upload url.
Create CSV file and input like table format on database. Ex : I use mahasiswa table. This image is mahasiswa table format :

Then create CSV file with sequence like mahasiswa table in database.

Well, now it's time to try it. Access site/uload url on your application!

Browse to CSV file.
Click save button to import data.
Please check in your table to view the result.


It's easy, isn't? Now you can implement this method to your application project. So good luck. Thank you. Wassalamualaikum Wr. Wb.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Tuesday, 11 August 2015

Export Data to Excel Without Extension on Yii2

 mumunotesss     12:59     Yii, Yii2     No comments   

Assalamualaikum Wr. Wb. Hello everybody. For along times i dont publish article. And now i will share to you all about export data table to excel file without extension.
Okay, lets go.
the first, add menu with url to /site/export in main.php.
Second, open SiteController file and change this code to it.
public function actionExport(){
    $model = Mahasiswa::find()->All();
    $filename = 'Data-'.Date('YmdGis').'-Mahasiswa.xls';
    header("Content-type: application/vnd-ms-excel");
    header("Content-Disposition: attachment; filename=".$filename);
    echo '<table border="1" width="100%">
        <thead>
            <tr>
                <th>Mim</th>
                <th>Nama</th>
                <th>Jurusan</th>
                <th>Angkatan</th>
                <th>Alamat</th>
                <th>Foto</th>
            </tr>
        </thead>';
        foreach($model as $data){
            echo '
                <tr>
                    <td>'.$data['nim'].'</td>
                    <td>'.$data['nama'].'</td>
                    <td>'.$data['jurusan'].'</td>
                    <td>'.$data['angkatan'].'</td>
                    <td>'.$data['alamat'].'</td>
                    <td><img src="'.Yii::$app->request->baseUrl.'/uploads/'.$data['foto'].'" width="100px"></td>
                </tr>
            ';
        }
    echo '</table>';

}
Well, now it's time to try it. Access your application!

Then click on menu export.
 result of export excel.

It's easy, isn't? Now you can implement this method to your application project. So good luck. Thank you. Wassalamualaikum Wr. Wb.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Saturday, 13 June 2015

Upload File or Image on Yii2

 mumunotesss     12:06     Yii, Yii2     No comments   

Assalamualaikum Wr. Wb. Good afternoon all. In this session, I would like to explain upload file or image on Yii2 application. Now, i use default Yii2 upload file.
I still using yii2basic application that created before. If you haven't develop that, please prefer this link to develop.
First, plase running this query or add fields foto to your mahasiswa table :

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Friday, 12 June 2015

Implementation google reCAPTCHA on Yii2 Application with Widget

 mumunotesss     14:12     Yii, Yii2     No comments   

Assalamualaikum Wr. Wb. Hello everybody...:D.
I published tutorial how to implementation captcha on Yii2, and then I will publish again my tutorial how to implementation google reCAPTCHA on Yii2 application with widget.
Fisrt, please run this code with composer :
      php composer.phar require --prefer-dist "himiklab/yii2-recaptcha-widget" "*"
or open your composer.json file and to require section :
    "himiklab/yii2-recaptcha-widget" : "*"
Run the composer update.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Implementation Captcha on Yii2

 mumunotesss     09:35     Yii, Yii2     No comments   

Assalamualaikum Wr. Wb. Hello everybody. Meet again with me in my blog. This session, I will share tutorial how to implementation captcha on Yii2. Let's start this session.
On this session, we still using yii2basic application that have been made a few days ago.
First, please open your LoginForm model class in models directory and change with following the code bellow:

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Thursday, 11 June 2015

Change password with validation and repeat password on Yii2

 mumunotesss     14:39     Yii, Yii2     No comments   



Hello everybody. I could not post an article because I didn't have new knowledge to share. Ok, this day I will share about "Change password with validation and repeat password on Yii2".
I still using the yii2basic applicaton. If you don't have it, please refer this for develop it.
If you have yii2basic application, then you must create PasswordForm.php file and save it in the models directory. Please add the code bellow.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Tuesday, 9 June 2015

Membuat Alert atau Notifikasi di Yii2

 mumunotesss     15:41     Yii, Yii2     No comments   

Selamat sore teman-teman. Mumpung lagi longgar, saya mau berbagi ilmu lagi. Kali ini tentang alert atau notifikasi. Alert atau notifikasi digunakan untuk memberikan pesan pada end user tentang action tersebut. Misalkan jika user menambahkan data. Dengan menggunakan notifikasi atau alert kita bisa memberikan informasi pada user apakah data tersebut berhasil disimpan atau gagal tersimpan. Enak kan teman-teman. Langsung aja ya.
Masih menggunakan aplikasi yii2basic yang telah kita buat. Jika teman-teman belum buat, teman-teman bisa lihat di postingan ane sebelumnya.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ACF (Access Control Filter) Yii2 dengan Role dari Database

 mumunotesss     10:37     Yii, Yii2     No comments   

Selamat pagi guys. Bertemu dengan saya kembali..hehehehe
Kembali lagi saya akan memberikan tutorial Yii2. Kali ini tentang ACF (Acess Control Filter) Yii2 dan cara implementasi sederhana di aplikasi Yii2.
Sebelum melakukan implementasi alangkah baiknya kita berkenalan dulu dengan ACF Yii2.
Access Control Filter (ACF) adalah metode autorisasi sederhana yang bagus digunakan pada aplikasi Yii2 yang hanya membutuhkan beberapa access control sederhana. Seperti pada namanya, ACF merupakan sebuah action filter yang dapat diimplementasikan pada controller atau module sebagai behavior. ACF akan mengecek access rules yang kita set apakah user tersebut diperbolehkan untuk mengakses action atau tidak.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Monday, 8 June 2015

Membuat fungsi CRUD dengan Gii Yii2

 mumunotesss     10:25     Yii, Yii2     No comments   

Selamat pagi guys. Setelah kemaren kita membuat login dari database, hari ini kita akan membuat CRUD (create, read, update, delete) dengan menggunakan modul generator dari yii yaitu Gii.
Apa sih Gii itu? Gii adalah sebuah modul yang dikembangkan oleh developer framework Yii yang bertujuan memudahkan para developer web maupun aplikasi web dalam mengenerate kode program awal meliputi create, read, update, delete data dari database.
Jadi jika kita ingin membuat fungsi tersebut kita tinggal memakai modul Gii dan tinggal kita custom sesuai keinginan kita. Enakan pakai Yii.
Dalam Gii terdapat 6 fungsi generator antara lain :

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Saturday, 6 June 2015

Membuat login Yii2 dengan Database

 mumunotesss     09:25     Yii, Yii2     No comments   


Selamat pagi guys. Sorry beberapa hari kamaren sibuk. Jadi belum sempet update blog lagi. Mumpung kali ini sempet, hari ini mau berbagi tentang cara login ke aplikasi Yii2 dengan user dari database.
Kemaren sudah ada penjelas mengenai penggunaan database yaitu menampilkan data dari database ke aplikasi Yii2. Langsung saja guys, kita mulai membuat login aplikasi Yii2 dari user yang ada di database.

Membuat Table Login.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Wednesday, 20 May 2015

Aplikasi Yii 2 dengan database

 mumunotesss     15:17     Yii, Yii2     No comments   

Selamat sore guys, menyambung tutorial sebelumnya. Kali ini kita akan membuat aplikasi dan menghubungkannya dengan database. Tapi untuk saat ini, kita hanya menampilkan data dari database ke aplikasi. Untuk menampilkan data kita perlu konfigurasi database, dan untuk memanipluasi data kita gunakan ActiveRecord. Oke langsung saja.

Berkerja dengan Database

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Tuesday, 19 May 2015

Hello World Yii 2

 mumunotesss     14:42     Yii, Yii2     No comments   

Oke selamat sore guys. Sudah beberapa hari gak posting nih. Hari ini mau ngasih tutorial awal coding. Kita akan mempelajari gimana membuat view dan controller dan menampilkannya. Untuk saat ini kita belum menggunakan model. Oke langsung aja guys keburu malem..:D

Katakan Hello

Sesi ini menjelaskan bagaimana membuat "Hello" baru di aplikasimu. Untuk itu, kamu akan membuat sebuah "action" dan "view".
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Wednesday, 13 May 2015

Menginstal Yii versi 2

 mumunotesss     14:59     Yii, Yii2     No comments   

Setelah kemarin kita membahas gimana sih caranya menginstall Yii versi 1, sekerang kita membahas gimana caranya menginstall Yii versi 2. Are you ready guests? Oke langsung saja kita mulai langkah-langkahnya.

Instalasi Yii

Kamu dapat menginstall Yii dengan 2 cara, menggunakan manajer paket composer atau mengunduh file arsip. Cara pertama lebih disukai, karena memungkinkan kamu untuk menginstall ekstensi baru atau  memperbarui Yii dengan satu perintah.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Thursday, 7 May 2015

Menginstal aplikasi Yii versi 1

 mumunotesss     14:51     Yii, Yii1     No comments   

Selamat siang menjelang sore guys. Kembali bertemu saya lagi. Setelah mengenal apa itu Yii, saya kembali lagi untuk memberikan tutorial penginstalan aplikasi Yii. Oke langsung saja guys.

Untuk menginstal aplikasi Yii, kamu harus mengunduh masternya terlebih dahulu website Yii (klik disini). Download aja yang versi 1 terbaru. Untuk detailnya bisa lihat gambar dibawah.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Wednesday, 6 May 2015

Mengenal Framework Yii

 mumunotesss     15:58     Yii, Yii1, Yii2     No comments   

Selamat siang menjelang sore guys. Saya sedang belajar Yii dan ingin berbagi ilmu kepada teman-teman. Pasti teman-teman sudah ada yang tau apa sih Yii itu. Oke langsung aja guys gak terlalu banyak mengoceh.

Apakah sih Yii?
Yii adalah perfoma tinggi, berbasis komponen framework PHP untuk membangun aplikasi web modern dengan cepat. Nama Yii (dilafalkan Yee atau [ji:]) berarti "sederhana dan evolusioner" dalam bahasa china. Yii juga dapat dianggap akronim dari Yes It Is!

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Home

About Me

mumunotesss
View my complete profile

Popular Posts

  • Change password with validation and repeat password on Yii2
    Hello everybody. I could not post an article because I didn't have new knowledge to share. Ok, this day I will share about "...
  • Import Data from CSV File to Database Without Extension in Yii2
    Hello everybody, Assalamualaikum Wr. Wb. Nearly 1 month I don't publish article. Now, I publish an article about " Import Data fro...
  • Membuat login Yii2 dengan Database
    Selamat pagi guys. Sorry beberapa hari kamaren sibuk. Jadi belum sempet update blog lagi. Mumpung kali ini sempet, hari ini mau berbagi te...
  • Membuat fungsi CRUD dengan Gii Yii2
    Selamat pagi guys. Setelah kemaren kita membuat login dari database, hari ini kita akan membuat CRUD (create, read, update, delete) dengan ...

Blog Archive

  • ▼  2015 (16)
    • ▼  November (1)
      • Export Data to PDF with MPDF Extension
    • ►  September (1)
      • Import Data from CSV File to Database Without Exte...
    • ►  August (1)
      • Export Data to Excel Without Extension on Yii2
    • ►  June (8)
      • Upload File or Image on Yii2
      • Implementation google reCAPTCHA on Yii2 Applicati...
      • Implementation Captcha on Yii2
      • Change password with validation and repeat passwor...
      • Membuat Alert atau Notifikasi di Yii2
      • ACF (Access Control Filter) Yii2 dengan Role dari ...
      • Membuat fungsi CRUD dengan Gii Yii2
      • Membuat login Yii2 dengan Database
    • ►  May (5)
      • Aplikasi Yii 2 dengan database
      • Hello World Yii 2
      • Menginstal Yii versi 2
      • Menginstal aplikasi Yii versi 1
      • Mengenal Framework Yii

Translate

Copyright © mumunotes
Distributed By My Blogger Themes | Blogger Theme By NewBloggerThemes