Answer the question
In order to leave comments, you need to log in
Yii2 how to display multiple values in Select 2 dropdown list kartik?
Hello! Please help me with a simple issue. I display data in the form in a drop-down list from another table using the Select2 kartik widget for Yii2 ,
echo $form->field($model, 'judge_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map(\backend\models\Judge::find()->where(['status'=>1])->asArray()->all(), 'id', 'last_name'),
'language' => 'ru',
'options' => ['placeholder' => 'Выберите судью...'],
'pluginOptions' => [
'allowClear' => false
],
class JudgeComitet extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'judge_comitet';
}
......
/**
* @return \yii\db\ActiveQuery
*/
public function getJudge()
{
return $this->hasOne(Judge::className(), ['id' => 'judge_id']);
}
public function getFullName()
{
return $this->judge->last_name.' '.$this->judge->name.' '.$this->judge->middle_name;
}
}
public function getFullName()
{
return $this->judge->last_name.' '.$this->judge->name.' '.$this->judge->middle_name;
}
Answer the question
In order to leave comments, you need to log in
ArrayHelper::map works great with both arrays and objects, in your case the getFullName method only works in the context of an object, so it makes no sense to select data as an array, replace
on the
PS Forming queries to the database in the View is shit code. So you better take them somewhere else
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question