1

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 ?

Malki Mohamed
  • 1,578
  • 2
  • 23
  • 40

1 Answers1

1

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...']);
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • my model Semaine extends \yii\db\ActiveRecord, and the findAllBySql is not define in this class, when I put it, that dispaly an error `Call to undefined method backend\models\Semaine::findAllBySql()` – Malki Mohamed Apr 17 '16 at 11:05
  • Please explain me your yii framework configuration .. because CHtml is form yii1 and ActiveRecord is from Yii2 while CActiveRecord instead have findAllBySql ... – ScaisEdge Apr 17 '16 at 15:59
  • yes I use yii 2, and it hadn't CHtml, I got it (CHtml) from github juste to use the activeDropDownList – Malki Mohamed Apr 17 '16 at 20:08
  • Then if you use Yii2 ... you don't nedd CHtml ... i have update the answer – ScaisEdge Apr 18 '16 at 05:35