Yii:: Create dropdownlist data through function

Posted: December 5, 2012 in Php, Yii Framework
Tags: , ,

Yii:: Create dropdownlist data through function

A. In your form:

<?php echo $form->dropDownList($model, 'report_to', Staff::model()->getApprovalList()); ?>

B. In your model file:

public function getApprovalList()
        {
            $list = array();
            $records = Staff::model()->findAll("leave_approval = 'Y'");
            $list = CHtml::listData($records, 'staff_id', 'name');             
            return $list;
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s