Tutorial selanjutnya adalah membuat aplikasi database dengan Yii:

  1. Masuk command line dan jalankan

    D:\home\yii\public_html>..\yii\framework\yiic webapp db
    Create a Web application under ‘D:\home\yii\public_html\db’? [Yes|No] yes
          mkdir D:/home/yii/public_html/db
          mkdir D:/home/yii/public_html/db/assets
          mkdir D:/home/yii/public_html/db/css
       generate css/bg.gif
       generate css/form.css
       generate css/ie.css
       generate css/main.css
       generate css/print.css
       generate css/screen.css
          mkdir D:/home/yii/public_html/db/images
       generate index-test.php
       generate index.php
          mkdir D:/home/yii/public_html/db/protected
       generate protected/.htaccess
          mkdir D:/home/yii/public_html/db/protected/commands
          mkdir D:/home/yii/public_html/db/protected/commands/shell
          mkdir D:/home/yii/public_html/db/protected/components
       generate protected/components/Controller.php
       generate protected/components/UserIdentity.php
          mkdir D:/home/yii/public_html/db/protected/config
       generate protected/config/console.php
       generate protected/config/main.php
       generate protected/config/test.php
          mkdir D:/home/yii/public_html/db/protected/controllers
       generate protected/controllers/SiteController.php
          mkdir D:/home/yii/public_html/db/protected/data
       generate protected/data/schema.mysql.sql
       generate protected/data/schema.sqlite.sql
       generate protected/data/testdrive.db
          mkdir D:/home/yii/public_html/db/protected/extensions
          mkdir D:/home/yii/public_html/db/protected/messages
          mkdir D:/home/yii/public_html/db/protected/models
       generate protected/models/ContactForm.php
       generate protected/models/LoginForm.php
          mkdir D:/home/yii/public_html/db/protected/runtime
          mkdir D:/home/yii/public_html/db/protected/tests
       generate protected/tests/bootstrap.php
          mkdir D:/home/yii/public_html/db/protected/tests/fixtures
          mkdir D:/home/yii/public_html/db/protected/tests/functional
       generate protected/tests/functional/SiteTest.php
       generate protected/tests/phpunit.xml
          mkdir D:/home/yii/public_html/db/protected/tests/report
          mkdir D:/home/yii/public_html/db/protected/tests/unit
       generate protected/tests/WebTestCase.php
          mkdir D:/home/yii/public_html/db/protected/views
          mkdir D:/home/yii/public_html/db/protected/views/layouts
       generate protected/views/layouts/column1.php
       generate protected/views/layouts/column2.php
       generate protected/views/layouts/main.php
          mkdir D:/home/yii/public_html/db/protected/views/site
       generate protected/views/site/contact.php
       generate protected/views/site/error.php
       generate protected/views/site/index.php
       generate protected/views/site/login.php
          mkdir D:/home/yii/public_html/db/protected/views/site/pages
       generate protected/views/site/pages/about.php
       generate protected/yiic
       generate protected/yiic.bat
       generate protected/yiic.php
          mkdir D:/home/yii/public_html/db/themes
          mkdir D:/home/yii/public_html/db/themes/classic
          mkdir D:/home/yii/public_html/db/themes/classic/views
       generate themes/classic/views/.htaccess
          mkdir D:/home/yii/public_html/db/themes/classic/views/layouts
          mkdir D:/home/yii/public_html/db/themes/classic/views/site
          mkdir D:/home/yii/public_html/db/themes/classic/views/system

    Your application has been created successfully under D:\home\yii\public_html\db.

    D:\home\yii\public_html>

  2. Kita akan membuat database dengan konfigurasi
    namadatabase: cobayii
    username: yii
    Password: framework
  3. Kita akan membuat tabel tbl_user dengan sql seperti di ./public_html/db/protected/data/schema.mysql.sql yang isinya:
    CREATE TABLE tbl_user (
        id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
        username VARCHAR(128) NOT NULL,
        password VARCHAR(128) NOT NULL,
        email VARCHAR(128) NOT NULL
    );

    INSERT INTO tbl_user (username, password, email) VALUES (‘test1’, ‘pass1’, ‘test1@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test2’, ‘pass2’, ‘test2@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test3’, ‘pass3’, ‘test3@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test4’, ‘pass4’, ‘test4@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test5’, ‘pass5’, ‘test5@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test6’, ‘pass6’, ‘test6@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test7’, ‘pass7’, ‘test7@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test8’, ‘pass8’, ‘test8@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test9’, ‘pass9’, ‘test9@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test10’, ‘pass10’, ‘test10@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test11’, ‘pass11’, ‘test11@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test12’, ‘pass12’, ‘test12@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test13’, ‘pass13’, ‘test13@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test14’, ‘pass14’, ‘test14@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test15’, ‘pass15’, ‘test15@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test16’, ‘pass16’, ‘test16@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test17’, ‘pass17’, ‘test17@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test18’, ‘pass18’, ‘test18example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test19’, ‘pass19’, ‘test19example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test20’, ‘pass20’, ‘test20@example.com’);
    INSERT INTO tbl_user (username, password, email) VALUES (‘test21’, ‘pass21’, ‘test21@example.com’);

  4. Langkah selanjutnya adalah melakukan generate CRUD code Gii

Kunjungi www.proweb.co.id untuk menambah wawasan anda.

Membuat aplikasi database Yii