Membuat ENUM Drop Down List

1. buat file di folder components dengan nama ZHtml.php (..\components\ZHtml.php)
2. isi file ZHtml.php dengan syntax berikut

<?php class ZHtml extends CHtml
{
    public static function enumDropDownList($model, $attribute, $htmlOptions=array())
    {
      return CHtml::activeDropDownList( $model, $attribute, self::enumItem($model,  $attribute), $htmlOptions);
    }
 
    public static function enumItem($model,$attribute) {
        $attr=$attribute;
        self::resolveName($model,$attr);
        preg_match('/\((.*)\)/',$model->tableSchema->columns[$attr]->dbType,$matches);
        foreach(explode("','", $matches[1]) as $value) {
                $value=str_replace("'",null,$value);
                $values[$value]=Yii::t('enumItem',$value);
        }
        return $values;
    } 
} ?>
3. save file ZHtml.php
4. gunakan di file view yg diinginkan dengan syntax berikut
<?php echo ZHtml::enumDropDownList( $model,'color' ); ?>
(syntax warna merah sesuaikan dengan kolom yg bertipe ENUM)


 

Menambahkan menu link di YII

  • Buka file main.php di \protected\views\layouts\main.php
  • Cari syntax berikut
<?php $this->widget('zii.widgets.CMenu',array(

Setting GII pada YII

  • Buka file main.php di \protected\config\main.php
  • Cari syntax berikut
/*
'modules'=>array(

Setting koneksi database di YII

  • Buka file main.php di \protected\config\main.php
  • Cari syntax ini
'db'=>array(

Ubah nama header web di YII

  • Buka file main.php di \protected\config\main.php
  • Cari syntax ini
'name'=>'My Web Application',

Login YII menggunakan database MySQL

  • Buka file UserIdentity.php di \protected\components\UserIdentity.php
  • Cari syntax ini, beri tanda comment di syntax nya dengan /* */ menjadi seperti ini
/*
public function authenticate()