Hello, I’m new using yii2, I’m learning too much about this incredible framework.
I’m working with kartik gridview and I need to show related data by row, not using implode or join but I can’t do it yet.
my tables:
Person:
id_person pk
id_degree fk
lu fk
name
lastname
…
Important: id_degree & lu = 1 person
academics
id_academic
id_degree fk
lu fk
cod_uni_academic
cod_title
…
analytical:
id_analytical
id_degree fk
lu fk
subject
…
…
Important: 1 person -> many subjects
So this is my model Person::
public function getAcademic()
{
return $this->hasOne(Academics::className(), ['id_carrera' => 'id_carrera', 'lu' => 'lu']);
}
public function getCod_uni_academica()
{
return $this->academics->cod_uni_academic;
}
public function getCod_title()
{
return $this->academics->cod_title;
}
.
.
.... more functions
public function getAnalytical()
{
return $this->hasMany(Analytical::className(), ['id_degree => 'id_degree', 'lu' => 'lu']);
}
my view index.php
$analiticos = GridView::widget([
'id' => 'gridAnaliticos',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'options' => [ 'style' => 'table-layout: fixed;'],
'headerRowOptions' => ['class' => 'kartik-sheet-style'],
'filterRowOptions' => ['class' => 'kartik-sheet-style'],
'columns' => [
[
'class' => '\kartik\grid\CheckboxColumn',
'headerOptions' => ['class' => 'kartik-sheet-style'],
],
'name',
'lastname',
[
'attribute'=>'subjects',
'headerOptions' => ['style' => 'width:30%'],
'format' => 'html',
'value' => function ($model) {
$output = '';
foreach($model->analytical as $row) {
$output .= $row->subject."<br />";
}
return $output;
},
],
Now, I show in datagridview all rows concatenated like this image:
But I need show subject by row, something like that:
This is posible?
Thank you in advance