[yii]Fetch data from database and create listbox in yii

<?php
    $records = User::model()->findAll();
    $list = CHtml::listData($records, 'id', 'username');
    echo CHtml::dropDownList('names', null, $list, array('empty' => '(Select a name)'));
?>

 

posted @ 2013-12-18 09:05  zaric  阅读(189)  评论(0编辑  收藏  举报