Answer the question
In order to leave comments, you need to log in
Best way to get dropdown items in Yii2?
There is a table with the fields `id`, `name`, `another`, `fields`....
I want to get the view array through the ActiveRecord interface: [id => name, id => name]
I know how to get the view array:
[ id => [ name => 'value' ] , id => [ name => 'value' ] ]
Model::find->all()->indexBy('id');
Answer the question
In order to leave comments, you need to log in
public static function getList()
{
return static::find()
->select(['name', 'id'])
->indexBy('id')
->asArray()
->column();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question