Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii and database row in dropdown

Tags:

yii

I have two model: test1 , test2 And an action in test1 :

public function active_widgets_list()
{
    $widgets = SiteWidget::model()->find('status=:status', array(':status' => '1'));
    return $widgets;
}

And I will show test1.tbl_1 rows as dropdown list in test2's view:

$list=CHtml::listData(SiteWidget::model()->active_widgets_list(), 'id', 'title');
echo $form->dropDownList($model,'widget_id', $list, array('empty' => 'Select Please'));

but down't work. i have just an empty dropdown.

like image 483
Chalist Avatar asked Oct 21 '22 21:10

Chalist


1 Answers

You should be using findAll instead of find, since find returns only a single active record with the specified condition.

$widgets = SiteWidget::model()->findAll('status=:status', array(':status' => '1'));
like image 186
bool.dev Avatar answered Oct 25 '22 19:10

bool.dev