Malki Mohamed
Malki Mohamed

Reputation: 1688

get value of CHtml::activeDropDownList in yii

I have this code

<?php echo CHtml::activeDropDownList(
                            $semaineModel,
                            'libelleSemaine',
                             CHtml::listData(Semaine::findBySql('SELECT * FROM Semaine')->all(), 'idSemine', 'libelleSemaine')
                        ); ?>

but why that displays just the last element of the table, and me I have 6 items in this table 'Semaine 1' to 'Semaine 6' and that code display just 'Semaine 6'. an idea please ?

Upvotes: 1

Views: 355

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

Then you don't nedd CHtml but active dropDownList Assiming your Semain model is named Semain

    use app\models\Semaine;
    use yii\helpers\ArrayHelper;      

    $semaines=Semaine::find()->all();
    $listSemaines = $listData=ArrayHelper::map($semaines,'idSemine', 'libelleSemaine');
    echo $form->field($model, 'idSemaine')->dropDownList( $listSemaines, 
               ['prompt'=>'Select Semaine...']);

Upvotes: 1

Related Questions