Код: Выделить всё
$humans = Humans::find()->select(['humans.id', 'lastname','name','fname','email','gender'])->joinWith('organization');
$dataProvider = new ActiveDataProvider([
'query' => $humans,
'pagination' => [
'pageSize' => 20,
],
]);
return $this->render('search', [
'dataProvider' => $dataProvider,
'model' => $model,
]);
Код: Выделить всё
/**
* @return \yii\db\ActiveQuery
*/
public function getOrganization()
{
return $this->hasOne(HumanOrganizations::className(), ['humanid' => 'id'])->select(['work_place','position']);
}
Код: Выделить всё
app\models\db\Humans#1
(
[yii\db\BaseActiveRecord:_attributes] => [
'id' => 10174036
'lastname' => 'Иванов'
'name' => 'Иван'
'fname' => 'Иванович'
'email' => '[email protected]'
'gender' => 'муж'
]
[yii\db\BaseActiveRecord:_oldAttributes] => [
'id' => 10174036
'lastname' => 'Иванов'
'name' => 'Иван'
'fname' => 'Иванович'
'email' => '[email protected]'
'gender' => 'муж'
]
[yii\db\BaseActiveRecord:_related] => [
'organization' => app\models\db\HumanOrganizations#2
(
[yii\db\BaseActiveRecord:_attributes] => [
'work_place' => 'Работа'
'position' => 'Работник'
]
[yii\db\BaseActiveRecord:_oldAttributes] => [
'work_place' => 'Работа'
'position' => 'Работник'
]
[yii\db\BaseActiveRecord:_related] => []
[yii\base\Model:_errors] => null
[yii\base\Model:_validators] => null
[yii\base\Model:_scenario] => 'default'
[yii\base\Component:_events] => []
[yii\base\Component:_behaviors] => []
)
]
[yii\base\Model:_errors] => null
[yii\base\Model:_validators] => null
[yii\base\Model:_scenario] => 'default'
[yii\base\Component:_events] => []
[yii\base\Component:_behaviors] => []
)
Код: Выделить всё
echo GridView::widget([
'dataProvider' => $dataProvider,
'tableOptions' => ['class' => 'table table-hover table-striped'],
'layout' => "<form id=\"humans_table\" method=\"POST\">{items}\n</form><div align=\"center\">{pager}\n<br />\n{summary}</div>",
'columns' => [
['label' => '',
'format' => 'raw',
'value' => function($data){
return '<label class="checkbox">
<input type="checkbox" name="uschk_' . $data->id . '" value="' . $data->id . '" data-toggle="checkbox">
</label>'; }
], ['class' => 'yii\grid\SerialColumn'],
'lastname:text:Фамилия',
'name:text:Имя',
'fname:text:Отчество',
'gender:text:Пол',
'email:text:EMail',
'organization.work_place:text:Место работы',
'organization.position:text:Должность',
['label' => '',
'format' => 'raw',
'value' => function($data){
return '<button type="button" rel="tooltip" title="Редактировать" class="btn btn-info btn-simple btn-xs">' . Html::a(' ', yii\helpers\Url::to(['pprog/edit', 'user' => $data->id]), ['class' => 'fa fa-edit']) . '</button>'; }
]
],
]);