Generate DropdownList from database .

In order to create a dropdownList with data from db, you have to combine it with listData method that will format models from db into array of $key=>$value.

This part is equal to listData Example :

// retrieve the models from db
$models = categories::model()->findAll(
                 array('order' => 'category_name'));
// format models as $key=>$value with listData
$list = CHtml::listData($models, 
                'category_id', 'category_name');
Now, we generate our dropdowList from the $list variable
<?php echo CHtml::dropDownList('categories', $category, 
              array('empty' => '(Select a category'));

Posting Lama Posting Lebih Baru

Comments :

ada 0 komentar ke “CHtml::dropDownList - Select Query From Database | YII”

Poskan Komentar

Copyright © 2014 - Aldi Ferdiyan - My Facebook - Powered By Pasa Iklan / Pasang Iklan Gratis

"CHtml::dropDownList - Select Query From Database | YII"

Sewa Laptop - Penyewaan Laptop - Sewa Laptop di jakarta - Warta kesehatan - Warta Sehat - Profil - Seks - alkes lab - Obat Penyakit Ibu Anak