Tutorial YII : CRUD (Create,Read,Update,Delete) Aplikasi sederhana yii

Tutorial Belajar Php Framework YII : Membuat aplikasi CRUD (Create,Read,Update,Delete) sederhana yii framework php, tutorial yii khusus pemula di sector code

Tutorial Php Framework Yii - Belajar aplikasi sederhana menggunakan php framework terpopuler di Indonesia yii framework, ya yii framework merupakan php framework populer untuk sekarang, banyak programer yang berpindah ke yii framework dikarenakan banyak hal, diantaranya yii framework memudahkan bagi pengguna baru dalam framework dalam belajar, bagi kamu yang belum mengetahui bagaimana cara menginstall yii 2.0 di localhost silahkan baca-baca kembali tutorial Php Framework yang sudah kami bahas di PHP Framework : Install Yii 2 di Windows Via Composer. Untuk membuat aplikasi CRUD sederhana menggunakan Yii simak terus tutorial ini ya, nanti akan dijelaskan dari awal sampai selesai.
Tutorial YII : CRUD (Create,Read,Update,Delete) Aplikasi sederhana yii

Membuat Database MySQL.

Dalam membuat aplikasi apapun hal terpenting yang harus kamu lakukan pertama kali adalah membuat database, dan dalam tutorial ini saya sudah membuat database MySQL, silahkan baca Tutorial Lengkap Cara Membuat Database MySQL di PhpMyAdmin. Silahkan baca tutorial membuat database mysql dan buatlah sebuah database sesuai kebutuhan aplikasi crud kamu nantinya.

Lanjut ke Yii framework.

Membuat Aplikasi CRUD Yii

Jika kamu sudah menginstall framework Yii, langsung saja buka url http://localhost/yii/basic/web/index.php?r=gii, kelebihan dari yii salahsatunya mempunyai gii, yaitu pembuatan code secara otomatis, jadi kita akan membuat Model, Controller, Form, Module dan Extensions serta aplikasi crud dibuat dari gii yii. jika settingan gii kamu belum enable silahkan edit pada folder web/index.php
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true); // jika gii false set ke true
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');

$config = yiihelpersArrayHelper::merge(
    require(__DIR__ . '/../../common/config/main.php'),
    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
);

$application = new yiiwebApplication($config);
$application->run();

Membuat Model

Sebelum membuat model, setting dulu nama database, user dan password yang sudah kamu buat sebelumnya pada folder common/config/main-local.php.
<?php
return [
    'components' => [
        'db' => [
            'class' => 'yiidbConnection',
            'dsn' => 'mysql:host=localhost;dbname=penjualan', // nama database kamu
            'username' => 'root', // user database
            'password' => '', // password
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yiiswiftmailerMailer',
            'viewPath' => '@common/mail',
            // 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,
        ],
    ],
];
Selanjutnya kita akan memvuat model, klik pada menu Model Generator. Isikan nama tabel yang akan kita buat aplikasi CRUD, dalam contoh ini saya akan membuat crud dengan nama tabel as_products dan ini hasil model AsProducts.php yang barusan dibuat.
<?php

namespace appmodels;

use Yii;

/**
 * This is the model class for table "as_products".
 *
 * @property integer $productID
 * @property integer $supplierID
 * @property integer $categoryID
 * @property integer $brandID
 * @property string $productBarcode
 * @property string $productName
 * @property string $productImei
 * @property integer $productBuyPrice
 * @property integer $productSalePrice
 * @property integer $productDiscount
 * @property integer $productStock
 * @property string $productNote
 * @property string $createdDate
 * @property integer $createdUserID
 * @property string $modifiedDate
 * @property integer $modifiedUserID
 */
class AsProducts extends yiidbActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'as_products';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['supplierID', 'categoryID', 'brandID', 'productBarcode', 'productName', 'productImei', 'productBuyPrice', 'productSalePrice', 'productDiscount', 'productStock', 'productNote', 'createdDate', 'createdUserID', 'modifiedDate', 'modifiedUserID'], 'required'],
            [['supplierID', 'categoryID', 'brandID', 'productBuyPrice', 'productSalePrice', 'productDiscount', 'productStock', 'createdUserID', 'modifiedUserID'], 'integer'],
            [['productNote'], 'string'],
            [['createdDate', 'modifiedDate'], 'safe'],
            [['productBarcode'], 'string', 'max' => 20],
            [['productName'], 'string', 'max' => 100],
            [['productImei'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'productID' => 'Product ID',
            'supplierID' => 'Supplier ID',
            'categoryID' => 'Category ID',
            'brandID' => 'Brand ID',
            'productBarcode' => 'Product Barcode',
            'productName' => 'Product Name',
            'productImei' => 'Product Imei',
            'productBuyPrice' => 'Product Buy Price',
            'productSalePrice' => 'Product Sale Price',
            'productDiscount' => 'Product Discount',
            'productStock' => 'Product Stock',
            'productNote' => 'Product Note',
            'createdDate' => 'Created Date',
            'createdUserID' => 'Created User ID',
            'modifiedDate' => 'Modified Date',
            'modifiedUserID' => 'Modified User ID',
        ];
    }
}
Selanjutnya kita akan membuat Form dengan gii juag, pilih menu Form Generator untuk membuat Form di yii.

Membuat Form Generator
Isikan nama Model class yang barusan kamu buat "app\models\AsProducts" dan nama view "products", dan berikut COde yang sudah kamu generate pada views\products.php
<?php

public function actionProducts()
{
    $model = new appmodelsAsProducts();

    if ($model->load(Yii::$app->request->post())) {
        if ($model->validate()) {
            // form inputs are valid, do something here
            return;
        }
    }

    return $this->render('products', [
        'model' => $model,
    ]);
}

Membuat Controllers

Pada Gii pilih menu Controller Generator dan isikan pada Controller Class "app\controllers\ProductsController" dan generete.
Berikut code dari ProductsController.php
<?php

namespace appcontrollers;

class ProductsController extends yiiwebController
{
    public function actionIndex()
    {
        return $this->render('index');
    }

}
dan views\product\index.php
<?php
/* @var $this yiiwebView */
?>
<h1>products/index</h1>

<p>
    You may change the content of this page by modifying
    the file <code><?= __FILE__; ?></code>.
</p>

CRUD Generator

Isiskan "app\models\AsProducts" pada Model Class dan "app\controllers\ProductsController" pada Controller Class

jika sukses silahkan buka
http://localhost/advanced/frontend/web/index.php?r=products%2Findex
http://localhost/advanced/frontend/web/index.php?r=products%2Fcreate

Pembuatan aplikasi CRUD sederhana dengan yii framework berhasil, jika ada pertanyaan silahkan berkomentar pada kotak komentar dibawah ya. terima kasih :)

COMMENTS


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,89,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,6,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Tutorial YII : CRUD (Create,Read,Update,Delete) Aplikasi sederhana yii
Tutorial YII : CRUD (Create,Read,Update,Delete) Aplikasi sederhana yii
Tutorial Belajar Php Framework YII : Membuat aplikasi CRUD (Create,Read,Update,Delete) sederhana yii framework php, tutorial yii khusus pemula di sector code
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQptqt-pgyz8vFqJG-CSyDR6e22DmQkFtkdyvyL4YJ_NmA6-ZcjHxh7b6g_C9jnDU2l47EgOf6fE7lCjMSST8XeuJpRoc2SN46sfINYWhEjlc7_9dklu_l-SQJI_eVDk4JBtKFHaxe3-k/s320/crud-yii-framework.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQptqt-pgyz8vFqJG-CSyDR6e22DmQkFtkdyvyL4YJ_NmA6-ZcjHxh7b6g_C9jnDU2l47EgOf6fE7lCjMSST8XeuJpRoc2SN46sfINYWhEjlc7_9dklu_l-SQJI_eVDk4JBtKFHaxe3-k/s72-c/crud-yii-framework.png
KODE AJAIB
https://scqq.blogspot.com/2015/11/tutorial-yii-crud-sederhana-khusus-pemula.html
https://scqq.blogspot.com/
https://scqq.blogspot.com/
https://scqq.blogspot.com/2015/11/tutorial-yii-crud-sederhana-khusus-pemula.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy