Home Ask Login Register

Developers Planet

Your answer is one click away!

Felipe Carrasco February 2016

Display data from related table & concatenate with column Yii2 SortableInput

I'm using the Kartik's SortableInput widget in a basic Yii2 app, I've been able to generate a list from a table in my db, but the items displayed only show the id of the rows in the tableA. What I want to do is to show a specific column from tableA and another column from tableB that is related to tableA (the relation and join exists in the modelSearch). This is what I have in my form:

    $items = [];
    $dosis = Dosis::find()
    foreach ($dosis as $key) {
        $items[$key->id_dosis] = [
            'content' => $key->id_dosis,
            'options' => ['data' => ['id_dosis'=>$key->id_dosis]],

<?= $form->field($model, 'dosis')->widget(SortableInput::classname(), [    
    'items' => $items,
    'hideInput' => false,
    'options' => ['class'=>'form-control', 'readonly'=>true]


Insane Skull February 2016

Use $key->relationName->fieldName:

foreach ($dosis as $key) {
    $items[$key->id_dosis] = [
        'content' => $key->relationName->fieldName,
        'options' => ['data' => ['id_dosis'=>$key->relationName->fieldName]],

Post Status

Asked in February 2016
Viewed 2,903 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life