//error:: htmlspecialchars() expects parameter 1 to be string, object given
//desc:: kartik Select2 expects date from getAllCountries() to in a certain format i dont understand
//view
<?= Select2::widget([
'name' => 'country_code',
'data' => Country::getAllCountries(),
'options' => [
'id' => 'country_select',
'multiple' => false,
'placeholder' => 'Choose...',
'class' =>
' uk-width-medium-7-10']
]);
?>
<?=
//Country model
/**
* @return \yii\db\ActiveQuery
*/
public function getAllCountries()
{
return Country::find()->orderby('country_name')->all();
}
?>
[color="#006400"]/* Moved from "General Discussions" to "Extensions" */[/color]
‘data’ should be an associative array where the keys are the option values and the values are the option label.
So your getAllCountries() must return something like:
[
1 => 'USA',
2 => 'Russia',
3 => 'Great Britain',
]
Check the following API reference.
http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#map()-detail