Cara Install Framework Yii2
Bagaimana cara Install Yii2?
Dalam lanjutan tutorial kita sebelumnya https://www.penyaircoding.com/2019/10/mengenal-framework-yii.html kita sudah mengenal apa itu Yii.
Catatan:
Disaat melakukan Instalasi penulis menggunakan Yii Versi2.
Bisa Menggunakan Composer atau ekstrak Zip.
XAMPP dengan Php Versi 7.0 sebagai web server
Tujuan catatan ini berguna untuk melanjutkan tutorial selanjutnya.
Disaat melakukan Instalasi penulis menggunakan Yii Versi2.
Bisa Menggunakan Composer atau ekstrak Zip.
XAMPP dengan Php Versi 7.0 sebagai web server
Tujuan catatan ini berguna untuk melanjutkan tutorial selanjutnya.
Langkah pertama dalam instalasi yii2, sobat bisa lansung download aplikasinya https://www.yiiframework.com/download , Yii2 sendiri memiliki dua project yaitu basic dan advanced, penulis akan memberikan tutorial bagaimana cara install yii advaced dengan menggunakan Composer, dan Basic dengan ekstrak Zip.
Apa perbedaan amtara Advanced dan Basic pada yii, berikut penjelasan nya:
No | Feature | Basic | Advanced |
---|---|---|---|
1 | Project structure | ✓ | ✓ |
2 | Site controller | ✓ | ✓ |
3 | User login/logout | ✓ | ✓ |
4 | Forms | ✓ | ✓ |
5 | DB connection | ✓ | ✓ |
6 | Console command | ✓ | ✓ |
7 | Asset bundle | ✓ | ✓ |
8 | Codeception tests | ✓ | ✓ |
9 | Twitter Bootstrap | ✓ | ✓ |
10 | Front- and back-end apps | ✓ | |
11 | Ready to use User model | ✓ | |
12 | User signup and password restore | ✓ |
- Pada advanced template mendukung aplikasi web frontend dan backend. Frontend adalah aplikasi web yang akan di tampilkan untuk end user. Backend adalah aplikasi web yang berfungsi untuk administrator dalam mengelola aplikasi frontend.
- Pada Advanced template sudah ada sistem autentikasi user yang siap untuk kita gunakan atau mudahnya, kita/user sudah bisa login dan logout tanpa kita harus membuat programnya.
- Pada Basic template sistem autensikasi user nya sudah ada tapi tanpa database/ pakai kode program saja.
Masuk proses instalasi:
Proses pertama penulis akan melakukan instalasi tempate advanced menggunakan composer.
Buka command prompt, pilih deriktori mana xampp di install lalu masuk ke folder htdocs (C:\xampp\htdocs) lalu copy-paste kode dibawah ini. ( harus tersambung koneksi internet )
php composer.phar create-project yiisoft/yii2-app-advanced advancedSeperti pada gambar dibawah ini:
Ketik cd/ pada command prompt kemudian cd/xampp/htdocs, maka akan muncul seperti gambar diatas. Kemudian tekan enter.
Proses instal yii2 advanced sedang berjalan. Tunggu sampai hasil download selesai.
Jika sudah selesai masuk ke folder htdocs kemudian cari folder advanced. Cari file init.bat klik 2 kali atau bisa klik kanan run administrator. Gambar seperti dibawah ini:
Pilih 0 untuk developmet kemudian ketik yes lalu enter.
Ketikan http://localhost/advanced/frontend/web/ di web browser sobat maka akan tampil seperti gambar dibawah ini.
Kemudian seperti janji penulis diatas, sekarang kita install template basic pada yii2 dengan mengekstrak ZIP dari hasil download. Download tempale basic disini https://www.yiiframework.com/download, pilih Yii 2 with basic apliaction template seperti gambar dibawah ini.
Maka otomatis file terdownload, ekstrak hasil download ke dalam folder htdocs pada XAMPP. Untuk melihat template basic ketik http://localhost/basic/web/. Maka hasil nya akan terlihat seperti gambar dibawa ini:
Untuk mengatasi error seperti gambar diatas, sobat bisa cari file web.php didalam folder config, kemudian isi cookieValidationKey dengan ketikan sembarang. Atau bisa Copy-Paste kode dibawah ini:
<?php $params = require __DIR__ . '/params.php'; $db = require __DIR__ . '/db.php'; $config = [ 'id' => 'basic', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'jdfhjdhjdthyjdjdgjdtr4325432552', ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => true, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => $db, /* 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], */ ], 'params' => $params, ]; if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yii\debug\Module', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; } return $config;
Di tutorial selanjutnya kita akan membuat login pada Yii2 tempalate advanced.
Sekian semoga artikel ini bermanfaat. Salam Coding.
Tidak ada komentar:
Write comments