0

I have a table with columns (id, name) whereas in name, I have name of months (january, february...) I want to take all this name and return it in dropdownlist where I can take one of month. I have this function in my model:

public function getMonths()
{
    $month= Months::find()
->asArray()
->all();

     for($monthNum = self::MY_START; $monthNum <= self::MY_MONTH; $monthNum++){
   return $month[$monthNum];
    }

}

Now it only returns me one month (2 february ). What should I do to return in this dropdown list only name of these months?

2

1 Answer 1

0

If you are using Yii2 you can simply use the dropdownlist in view

<?php
 use yii\helpers\ArrayHelper;
?>

<?= Html::activeDropDownList($model, 'your_month_id',
   ArrayHelper::map(Months::find()->all(), 'id', 'name')) ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.