Yii2:checkboxList不显示ArrayDataProvider

I want to use a checkboxList to show data from a data provider.

My view file:

$offices = Offices::findMyOffices();
echo Html::checkboxList('name', [], $offices);

My model file:

public static function findMyOffices()
{    
    $dataProvider = new ArrayDataProvider([
        'allModels' => 'SELECT id_office ...'
    ]);

    return $dataProvider;
}

But the view shows me the checkbox list with the sql query instead of the sql query's results:

My checkbox list showing my select query instead of results

I solve it using sqlDataProvider:

View:

$offices = Offices::findMyOffices();        
echo Html::checkboxList('name', [], ArrayHelper::map($offices, 'id_office', 'name_office'));

Model:

public static function findMyOffices()
{    
    $dataProvider = new sqlDataProvider([
        'sql' => 'SELECT id_office ...'
    ]);

    return $dataProvider->getModels();
}

ArrayDataProvider needs an array of items. you can add ->asArray() to your activequery.

$dataProvider = new ArrayDataProvider([
        'allModels' => [['id' => 1, 'title' => 'xxx, ...], ...],
    ]);

my favorite for fetching data for a dropdown is:

MyModel::find()->select('name', 'id')->indexBy('id')->column()